void finishEmulation() { if (MouseHookAPI.UnhookWindowsHookEx(MouseHookInfo.hHook) == false) { MessageBox.Show("UnhookWindowsHookEx Failed."); } }
void startEmulation() { using (Process process = Process.GetCurrentProcess()) using (ProcessModule module = process.MainModule) { MouseHookInfo.hHook = MouseHookAPI.SetWindowsHookEx( MouseHookInfo.WH_MOUSE_LL, mouse_proc = new MouseHookAPI.HookProcedureDelegate(MouseHookProc), MouseHookAPI.GetModuleHandle(module.ModuleName), 0); } if (MouseHookInfo.hHook == IntPtr.Zero) { MessageBox.Show("SetWindowsHookEx Failed."); } }
public IntPtr MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0) { MouseHookInfo.MouseHookStruct data = (MouseHookInfo.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookInfo.MouseHookStruct)); switch ((int)wParam) { case MouseHookInfo.WM_LBUTTONDOWN: { break; } case MouseHookInfo.WM_LBUTTONUP: { break; } } } return(MouseHookAPI.CallNextHookEx(MouseHookInfo.hHook, nCode, wParam, lParam)); }