Beispiel #1
0
        private static void KeyboardHookHandler(object data)
        {
            if (allHotkeysSuspendCount > 0)
            {
                return;
            }

            lock (keysLocker)
            {
                KeyboardHookData    hookData     = (KeyboardHookData)data;
                KeyboardMessageType keyState     = hookData.keyState;
                KBDLLHOOKSTRUCT     keyboardData = hookData.keyData;

                Keys newKeys         = (Keys)keyboardData.vkCode;
                Keys newModifierKeys = HotkeyUtils.GetModifierKeys(newKeys);

                if (keyState == KeyboardMessageType.WM_KEYDOWN || keyState == KeyboardMessageType.WM_SYSKEYDOWN)
                {
                    pressedModifierKeys |= newModifierKeys;

                    if (newKeys != pressedKey)
                    {
                        pressedKey = newKeys;
                        HandleHotkeys(newModifierKeys == Keys.None ? pressedKey : Keys.None);
                    }
                }
                else if (keyState == KeyboardMessageType.WM_KEYUP || keyState == KeyboardMessageType.WM_SYSKEYUP)
                {
                    pressedKey           = Keys.None;
                    pressedModifierKeys &= ~newModifierKeys;
                }
            }
        }
Beispiel #2
0
        public static string GetHotkeyName(Keys key, Keys modifiers)
        {
            string hotkeyName   = string.Empty;
            Keys   keyModifiers = HotkeyUtils.GetModifierKeys(modifiers);

            if ((keyModifiers & Keys.Control) == Keys.Control)
            {
                hotkeyName += "Ctrl + ";
            }
            if ((keyModifiers & Keys.Alt) == Keys.Alt)
            {
                hotkeyName += "Alt + ";
            }
            if ((keyModifiers & Keys.Shift) == Keys.Shift)
            {
                hotkeyName += "Shift + ";
            }

            hotkeyName += HotkeyUtils.GetKeyName(key & ~HotkeyUtils.modifierKeysMask);

            return(hotkeyName);
        }