public RMServer() { InterceptKeys ic = new InterceptKeys(); ic.HandleKey = (k, d) => { if (k == Keys.F1 && d) { sendMouse ^= true; return; } const int size = 5; byte[] send = new byte[size]; send[0] = d ? (byte)1 : (byte)0; BitConverter.GetBytes((int)k).CopyTo(send, 1); c.Send(send, size, Constants.BROADCAST, Constants.PORT); Console.WriteLine($"{(d ? "Down" : "Up")} {k}"); }; if (hHook == IntPtr.Zero) { Task.Run(() => { MouseHookProcedure = new DLLImport.HookProc(HandleMouse); using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { hHook = DLLImport.SetWindowsHookEx(Constants.WH_MOUSE_LL, MouseHookProcedure, DLLImport.GetModuleHandle(curModule.ModuleName), 0); } Application.Run(); }); } _ = StartServer(); }
private IntPtr SetHook(DLLImport.HookProc proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) { return(DLLImport.SetWindowsHookEx(Constants.WH_KEYBOARD_LL, proc, DLLImport.GetModuleHandle(curModule.ModuleName), 0)); } }
public InterceptKeys() { Task.Run(() => { _proc = HookCallback; _hookID = SetHook(_proc); Application.Run(); DLLImport.UnhookWindowsHookEx(_hookID); }); }
public KeyboardInput() { keyBoardDelegate = KeyboardHookDelegate; keyBoardHandle = DLLImport.SetWindowsHookEx( WH_KEYBOARD_LL, keyBoardDelegate, IntPtr.Zero, 0); }