Example #1
0
        private int KeyboardHookHandler(int code, int wParam, IntPtr lParam)
        {
            try
            {
                if (code >= 0)
                {
                    Keys key      = (Keys)wParam;
                    bool keyState = GetAsyncKeyState(key);

                    if (key != lastKeyCode || keyState != lastKeyState)
                    {
                        lastKeyCode  = key;
                        lastKeyState = keyState;

                        KeyDefinition args = new KeyDefinition();

                        args.KeyCode     = key;
                        args.IsShiftDown = GetAsyncKeyState(Keys.ShiftKey);
                        args.IsCtrlDown  = GetAsyncKeyState(Keys.ControlKey);
                        args.IsAltDown   = GetAsyncKeyState(Keys.Menu);
                        args.KeyState    = (KeyState)(int)(keyState ? 1 : 0);

                        OnKeyboardEvent(args);
                    }
                }
            }
            catch (Exception err)
            {
                BatConsole.WriteError("Error in KeyboardHookHandler", err);
            }

            // Yield to the next hook in the chain
            return(CallNextHookEx(hookHandle, code, wParam, lParam));
        }
Example #2
0
 public bool Equals(KeyDefinition e)
 {
     return
         (KeyState == e.KeyState &&
          KeyCode == e.KeyCode &&
          IsAltDown == e.IsAltDown &&
          IsCtrlDown == e.IsCtrlDown &&
          IsShiftDown == e.IsShiftDown);
 }
Example #3
0
 private void OnKeyboardEvent(KeyDefinition args)
 {
     try
     {
         if (KeyboardEvent != null)
         {
             KeyboardEvent(args);
         }
     }
     catch { }
 }