protected void OnHookInvoked(Buffalo.Kernel.Win32.WindowsAPI.HookEventArgs e) { if (HookInvoked != null) { HookInvoked(this, e); } }
void hook_HookInvoked(object sender, Buffalo.Kernel.Win32.WindowsAPI.HookEventArgs e) { KBDLLHOOKSTRUCT keyboardHook = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(e.lParam, typeof(KBDLLHOOKSTRUCT)); KeyBoardType type = (KeyBoardType)e.wParam; if (e.HookCode >= 0) { int vkCode = keyboardHook.vkCode; switch (type) { case KeyBoardType.WM_KEYDOWN: DoKeyDown(vkCode); break; case KeyBoardType.WM_KEYUP: DoPress(vkCode); DoKeyUp(vkCode); break; case KeyBoardType.WM_SYSKEYDOWN: DoKeyDown(vkCode); break; case KeyBoardType.WM_SYSKEYUP: DoKeyUp(vkCode); break; default: break; } } }
// ************************************************************************ // ************************************************************************ // Default filter function protected IntPtr CoreHookProc(int code, IntPtr wParam, IntPtr lParam) { if (code < 0) { return(WindowsAPI.CallNextHookEx(m_hhook, code, wParam, lParam)); } // Let clients determine what to do Buffalo.Kernel.Win32.WindowsAPI.HookEventArgs e = new Buffalo.Kernel.Win32.WindowsAPI.HookEventArgs(); e.HookCode = code; e.wParam = wParam; e.lParam = lParam; OnHookInvoked(e); // Yield to the next hook in the chain return(WindowsAPI.CallNextHookEx(m_hhook, code, wParam, lParam)); }