private IntPtr HookFunc(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode < 0) { return(WindowsHookExInterop.CallNextHookEx(_hookId, nCode, wParam, lParam)); } var iwParam = wParam.ToInt32(); if (iwParam == WINDOW_MESSAGE.WM_KEYDOWN || iwParam == WINDOW_MESSAGE.WM_SYSKEYDOWN) { { var code = (VIRTUAL_KEY_CODE)Marshal.ReadInt32(lParam); var key = _mapper.Map <VIRTUAL_KEY_CODE, Key>(code); RaiseKeyEvent(new KeyEventArgs(key, KeyAction.KeyDown)); } } else if (iwParam == WINDOW_MESSAGE.WM_KEYUP || iwParam == WINDOW_MESSAGE.WM_SYSKEYUP) { { var code = (VIRTUAL_KEY_CODE)Marshal.ReadInt32(lParam); var key = _mapper.Map <VIRTUAL_KEY_CODE, Key>(code); RaiseKeyEvent(new KeyEventArgs(key, KeyAction.KeyUp)); } } return(WindowsHookExInterop.CallNextHookEx(_hookId, nCode, wParam, lParam)); }
private IntPtr HookFunc(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode < 0) { return(WindowsHookExInterop.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)); } var iwParam = wParam.ToInt32(); if (iwParam == (uint)WINDOW_MESSAGE.WM_KEYDOWN || iwParam == (uint)WINDOW_MESSAGE.WM_SYSKEYDOWN) { { var code = Marshal.ReadInt32(lParam); var key = KeyInterop.KeyFromVirtualKey(code); RaiseKeyEvent(new KeyEventArgs(key, KeyState.KeyDown)); } } else if (iwParam == (uint)WINDOW_MESSAGE.WM_KEYUP || iwParam == (uint)WINDOW_MESSAGE.WM_SYSKEYUP) { { var code = Marshal.ReadInt32(lParam); var key = KeyInterop.KeyFromVirtualKey(code); RaiseKeyEvent(new KeyEventArgs(key, KeyState.KeyUp)); } } return(WindowsHookExInterop.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam)); }