public LowLevelKeyboardHookProcArgs(int code, IntPtr wParam, IntPtr lParam) { HookCode = (HookCode)code; KeyEvent = (KeyEvent)wParam.ToInt32(); Info = (KeyEventInfo)Marshal.PtrToStructure(lParam, typeof(KeyEventInfo)); }
protected virtual IntPtr LowLevelKeyboardHookProc(HookCode hc, KeyEvent keyEvent, KeyEventInfo info) { try { string line = "\r\nHC: [" + hc.ToString() + "]\r\nKEY_EVENT: [" + keyEvent.ToString() + "]\r\n" + info.ToString(); LocalStaticLogger.WriteLine(line); Console.Out.WriteLine(line); foreach (var remappedKey in mappings.Keys) { // we fudge equality here, comparing a KeyPress to a KeyEvent, technically // they are not so much equal as equivalent if (info == remappedKey) { var mappedKey = mappings[remappedKey]; if (mappedKey != null) { if (keyEvent == KeyEvent.WM_KEYDOWN) { if (KeyEventSimulator.SimulateKeyDownAsync(mappedKey.VkCode, mappedKey.ScanCode, mappedKey.Extended)) { return(LowLevelKeyboardHook.HANDLED); } } else if (keyEvent == KeyEvent.WM_KEYUP) { if (KeyEventSimulator.SimulateKeyUpAsync(mappedKey.VkCode, mappedKey.ScanCode, mappedKey.Extended)) { return(LowLevelKeyboardHook.HANDLED); } } } } } } catch (Exception e) { LocalStaticLogger.WriteLine(e.ToString()); } return(IntPtr.Zero); }