Exemple #1
0
        public SpecialKeyState CheckModifiers()
        {
            SpecialKeyState state = new SpecialKeyState();

            if ((InterceptKeys.GetKeyState(VK_SHIFT) & 0x8000) != 0)
            {
                //SHIFT is pressed
                state.ShiftPressed = true;
            }
            if ((InterceptKeys.GetKeyState(VK_CONTROL) & 0x8000) != 0)
            {
                //CONTROL is pressed
                state.CtrlPressed = true;
            }
            if ((InterceptKeys.GetKeyState(VK_ALT) & 0x8000) != 0)
            {
                //ALT is pressed
                state.AltPressed = true;
            }
            if ((InterceptKeys.GetKeyState(VK_WIN) & 0x8000) != 0)
            {
                //ALT is pressed
                state.WinPressed = true;
            }

            return(state);
        }
Exemple #2
0
 public GloablHotkey()
 {
     // We have to store the LowLevelKeyboardProc, so that it is not garbage collected runtime
     hookedLowLevelKeyboardProc = LowLevelKeyboardProc;
     // Set the hook
     hookId = InterceptKeys.SetHook(hookedLowLevelKeyboardProc);
 }
Exemple #3
0
        private IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam)
        {
            bool continues = true;

            if (nCode >= 0)
            {
                if (wParam.ToUInt32() == (int)KeyEvent.WM_KEYDOWN ||
                    wParam.ToUInt32() == (int)KeyEvent.WM_KEYUP ||
                    wParam.ToUInt32() == (int)KeyEvent.WM_SYSKEYDOWN ||
                    wParam.ToUInt32() == (int)KeyEvent.WM_SYSKEYUP)
                {
                    if (hookedKeyboardCallback != null)
                        continues = hookedKeyboardCallback((KeyEvent)wParam.ToUInt32(), Marshal.ReadInt32(lParam), CheckModifiers());
                }
            }

            if (continues)
            {
                return InterceptKeys.CallNextHookEx(hookId, nCode, wParam, lParam);
            }
            return (IntPtr)1;
        }
Exemple #4
0
 public void Dispose()
 {
     InterceptKeys.UnhookWindowsHookEx(hookId);
 }