Exemplo n.º 1
0
 private static bool IsAltTabKeyCombination(LowLevelKeyboardMessage keyboardMessage)
 {
     return keyboardMessage.VirtualKeyCode == (int) Keys.Tab
            && keyboardMessage.Flags == AltDown;
 }
Exemplo n.º 2
0
        public static void KeyboardHook(LowLevelMessage evt, ref bool handled)
        {
            LowLevelKeyboardMessage kevt = evt as LowLevelKeyboardMessage;

            // Prevent further code execution when the key stroke hasn't changed
            if (_lastKeyboardMessage != null)
            {
                bool notchanged = (kevt.Message == _lastKeyboardMessage.Message)
                                  && (kevt.VirtualKeyCode == _lastKeyboardMessage.VirtualKeyCode)
                                  && (kevt.KeyboardEventFlags == _lastKeyboardMessage.KeyboardEventFlags)
                                  && (kevt.ExtraInfo == _lastKeyboardMessage.ExtraInfo);

                if (notchanged)
                    return;
            }
            _lastKeyboardMessage = kevt;

            // Get keyboard state
            switch ((KeyboardMessage)kevt.Message)
            {
                case KeyboardMessage.WM_KEYDOWN:
                case KeyboardMessage.WM_SYSKEYDOWN:
                    if (((VirtualKeys)kevt.VirtualKeyCode == VirtualKeys.LeftMenu) || ((VirtualKeys)kevt.VirtualKeyCode == VirtualKeys.RightMenu))
                        _isAltDown = true;
                    if (((VirtualKeys)kevt.VirtualKeyCode == VirtualKeys.LeftShift) || ((VirtualKeys)kevt.VirtualKeyCode == VirtualKeys.RightShift))
                        _isShiftDown = true;
                    if (((VirtualKeys)kevt.VirtualKeyCode == VirtualKeys.LeftControl) || ((VirtualKeys)kevt.VirtualKeyCode == VirtualKeys.RightControl))
                        _isControlDown = true;
                    break;
                case KeyboardMessage.WM_KEYUP:
                case KeyboardMessage.WM_SYSKEYUP:
                    if (((VirtualKeys)kevt.VirtualKeyCode == VirtualKeys.LeftMenu) || ((VirtualKeys)kevt.VirtualKeyCode == VirtualKeys.RightMenu))
                        _isAltDown = false;
                    if (((VirtualKeys)kevt.VirtualKeyCode == VirtualKeys.LeftShift) || ((VirtualKeys)kevt.VirtualKeyCode == VirtualKeys.RightShift))
                        _isShiftDown = false;
                    if (((VirtualKeys)kevt.VirtualKeyCode == VirtualKeys.LeftControl) || ((VirtualKeys)kevt.VirtualKeyCode == VirtualKeys.RightControl))
                        _isControlDown = false;
                    break;
            }
        }