Beispiel #1
0
        /// <summary>
        /// Hook process messages.
        /// </summary>
        /// <param name="nCode"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        static IntPtr HookProcFunction(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode == 0)
            {
                KBLLHOOKSTRUCT pKBLLHOOKSTRUCT = (KBLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBLLHOOKSTRUCT));
                switch (wParam.ToInt32())
                {
                case WM_KEYDOWN:
                    KeyboardDown?.Invoke(null, new KeyEventArgs((Keys)pKBLLHOOKSTRUCT.vkCode));
                    //MessageBox.Show("OKAY, " + pKBLLHOOKSTRUCT.vkCode); // <--- DEBUG
                    break;

                case WM_KEYUP:
                    KeyboardUp?.Invoke(null, new KeyEventArgs((Keys)pKBLLHOOKSTRUCT.vkCode));
                    break;

                default:
                    break;
                }
            }

            return(API.CallNextHookEx(hHook, nCode, wParam, lParam));
        }
Beispiel #2
0
 internal void InvokeKeyboardDown(KeyboardEventArgs args) => KeyboardDown?.Invoke(this, args);