internal GlobalKeyEventArgs(KBDLLHOOKSTRUCT keyData)
 {
     KeyCode = keyData.vkCode;
     KeyData = KeyInterop.KeyFromVirtualKey(keyData.vkCode);
     Flags = keyData.flags;
     ScanCode = keyData.scanCode;
     Time = keyData.time;
     Handled = false;
 }
 static extern IntPtr CallNextHookEx(IntPtr hHook, int nCode, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam);
        private static IntPtr HookProc(int nCode, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam)
        {
            bool handled = false;

            if (nCode == HC_ACTION)
            {
                GlobalKeyEventArgs event_args = new GlobalKeyEventArgs(lParam);
                switch (wParam.ToInt32())
                {
                    case WM_KEYDOWN:
                    case WM_SYSKEYDOWN:
                        CallEvent(KeyDown, event_args);
                        break;

                    case WM_KEYUP:
                    case WM_SYSKEYUP:
                        CallEvent(KeyUp, event_args);
                        break;
                }
                handled = event_args.Handled;
            }

            return handled
                ? (IntPtr) 1
                : CallNextHookEx(HookHandle, nCode, wParam, ref lParam);
        }