public MouseActivityArgs(MouseDevice device, MouseActivityType activityType, MouseButtonActivity buttonActivity, MouseCoordinateSpace space, MouseMovementType mmType, IntPtr windowHandle, int x, int y, short delta, int clicks, int keyflags) { Device = device; ActivityType = activityType; ButtonActivity = buttonActivity; CoordinateSpace = space; MovementType = mmType; WindowHandle = windowHandle; Clicks = clicks; X = x; Y = y; Delta = delta; KeyFlags = keyflags; }
public static MouseActivityType ConvertButtonActivityToMouseActivity(MouseButtonActivity mbActivity) { MouseActivityType maType = MouseActivityType.None; switch (mbActivity) { case MouseButtonActivity.LeftButtonDown: case MouseButtonActivity.RightButtonDown: case MouseButtonActivity.MiddleButtonDown: case MouseButtonActivity.Button4Down: case MouseButtonActivity.Button5Down: maType = MouseActivityType.MouseDown; break; case MouseButtonActivity.LeftButtonUp: case MouseButtonActivity.RightButtonUp: case MouseButtonActivity.MiddleButtonUp: case MouseButtonActivity.Button4Up: case MouseButtonActivity.Button5Up: maType = MouseActivityType.MouseUp; break; case MouseButtonActivity.MouseWheel: maType = MouseActivityType.MouseWheel; break; default: maType = MouseActivityType.MouseMove; break; } return maType; }
public static uint SimulateMouseActivity(int x, int y, int delta, MouseButtonActivity activity) { MouseEvents++; uint rv = 0; INPUT mouse_input = new INPUT(); mouse_input.type = User32.INPUT_MOUSE; mouse_input.mi.mouseData = delta; mouse_input.mi.dx = x; mouse_input.mi.dy = y; switch (activity) { case MouseButtonActivity.None: // No button activity is assumed to be a Move event mouse_input.mi.dwFlags |= (int)(User32.MOUSEEVENTF_ABSOLUTE | User32.MOUSEEVENTF_MOVE); break; case MouseButtonActivity.LeftButtonDown: mouse_input.mi.dwFlags |= (int)(User32.MOUSEEVENTF_LEFTDOWN); break; case MouseButtonActivity.LeftButtonUp: mouse_input.mi.dwFlags |= (int)(User32.MOUSEEVENTF_LEFTUP); break; case MouseButtonActivity.RightButtonDown: mouse_input.mi.dwFlags |= (int)(User32.MOUSEEVENTF_RIGHTDOWN); break; case MouseButtonActivity.RightButtonUp: mouse_input.mi.dwFlags |= (int)(User32.MOUSEEVENTF_RIGHTUP); break; case MouseButtonActivity.MiddleButtonDown: mouse_input.mi.dwFlags |= (int)(User32.MOUSEEVENTF_MIDDLEDOWN); break; case MouseButtonActivity.MiddleButtonUp: mouse_input.mi.dwFlags |= (int)(User32.MOUSEEVENTF_MIDDLEUP); break; case MouseButtonActivity.MouseWheel: mouse_input.mi.dwFlags |= (int)(User32.MOUSEEVENTF_WHEEL); break; default: break; } //InputHook.RealData = false; rv = SimulateInput(mouse_input); //InputHook.RealData = true; return rv; }