Пример #1
0
            /// <summary>
            /// Checks if the key that was let go is a modifier key. If it is, we set the values of shift, alt and ctrl accordingly. We also return the bool value of true if the key that was let go is a modifier and vice versa.
            /// </summary>
            /// <param name="e">Argument passed by the KeyboardPressed event found in the internal GlobalKeyboardHook class.</param>
            /// <returns>Returns true if the key that was let go is a modifier key. If otherwise, false.</returns>
            bool handleModifierKeyUp(GlobalKeyboardHookEventArgs e)
            {
                switch (e.KeyboardData.VirtualCode) //Check which Modifier Key was let go, set the appropriate variable back to not pressed state (none) and return true. Return False if the key wasn't a modifier key.
                {
                case VirtualKeycodes.LeftShift:
                    shift = ModifierKeySide.None;
                    return(true);

                case VirtualKeycodes.LeftAlt:
                    alt = ModifierKeySide.None;
                    return(true);

                case VirtualKeycodes.LeftCtrl:
                    ctrl = ModifierKeySide.None;
                    return(true);

                case VirtualKeycodes.RightCtrl:
                    ctrl = ModifierKeySide.None;
                    return(true);

                case VirtualKeycodes.RightShift:
                    shift = ModifierKeySide.None;
                    return(true);

                case VirtualKeycodes.RightAlt:
                    alt = ModifierKeySide.None;
                    return(true);

                default:
                    return(false);
                }
            }
Пример #2
0
            /// <summary>
            /// Checks if key pressed is a modifier key. If it is, we set the values of shift, alt and ctrl accordingly. We also return the bool value of true if the key pressed is a modifier and vice versa.
            /// </summary>
            /// <param name="e">Argument passed by the KeyboardPressed event found in the internal GlobalKeyboardHook class.</param>
            /// <returns>Returns true if the key that was pressed is a modifier key. False if otherwise.</returns>
            bool handleModifierKeyDown(GlobalKeyboardHookEventArgs e)
            {
                switch (e.KeyboardData.VirtualCode) //Check which Modifier Key was pressed, set the appropriate variable to the location of the modifier key that was pressed and return true. Return False if the key wasn't a modifier key.
                {
                case VirtualKeycodes.LeftShift:
                    shift = ModifierKeySide.Left;
                    return(true);

                case VirtualKeycodes.LeftAlt:
                    alt = ModifierKeySide.Left;
                    return(true);

                case VirtualKeycodes.LeftCtrl:
                    ctrl = ModifierKeySide.Left;
                    return(true);

                case VirtualKeycodes.RightCtrl:
                    ctrl = ModifierKeySide.Right;
                    return(true);

                case VirtualKeycodes.RightShift:
                    shift = ModifierKeySide.Right;
                    return(true);

                case VirtualKeycodes.RightAlt:
                    alt = ModifierKeySide.Right;
                    return(true);

                default:
                    return(false);
                }
            }
Пример #3
0
            //Handle the creation of an instance of this class. Set the values of the properties.
            internal GlobalKeyEventArgs(GlobalKeyboardHookEventArgs e, ModifierKeySide alt, ModifierKeySide ctrl, ModifierKeySide shift)
            {
                Alt              = alt;
                Control          = ctrl;
                Shift            = shift;
                KeyCode          = e.KeyboardData.VirtualCode;
                hardwareScanCode = e.KeyboardData.HardwareScanCode;

                //Set the IsModifierKey variable by checking if the KeyCode is a modifier key.
                IsModifierKey = (KeyCode == VirtualKeycodes.LeftShift || KeyCode == VirtualKeycodes.LeftCtrl || KeyCode == VirtualKeycodes.LeftAlt ||
                                 KeyCode == VirtualKeycodes.RightAlt || KeyCode == VirtualKeycodes.RightCtrl || KeyCode == VirtualKeycodes.RightShift);

                CharResult = GetCharFromKey(e);
            }