/// <summary> /// Send a mouse button up signal. /// <remarks>Errors will not be handled.</remarks> /// </summary> public static void SendMouseButtonUp(MouseButton button) { SafeNativeMethods.MOUSEINPUT mi = new SafeNativeMethods.MOUSEINPUT(); switch (button) { case MouseButton.Left: mi.dwFlags = SafeNativeMethods.MOUSEINPUTFLAGS.MOUSEEVENTF_LEFTUP; break; case MouseButton.Right: mi.dwFlags = SafeNativeMethods.MOUSEINPUTFLAGS.MOUSEEVENTF_RIGHTUP; break; default: throw new NotSupportedException(); } SafeNativeMethods.MOUSEKEYBDHARDWAREINPUT mkhInput = new SafeNativeMethods.MOUSEKEYBDHARDWAREINPUT { mi = mi }; SafeNativeMethods.INPUT input = new SafeNativeMethods.INPUT { type = SafeNativeMethods.INPUT_TYPE.MOUSE, mkhi = mkhInput }; SafeNativeMethods.SendInput(1, ref input, Marshal.SizeOf(input)); }
/// <summary> /// Send a mouse move signal. /// <remarks>Errors will not be handled.</remarks> /// </summary> public static void SendMouseMoveRelative(int x, int y) { SafeNativeMethods.MOUSEINPUT mi = new SafeNativeMethods.MOUSEINPUT { dwFlags = SafeNativeMethods.MOUSEINPUTFLAGS.MOUSEEVENTF_MOVE, dx = x, dy = y }; SafeNativeMethods.MOUSEKEYBDHARDWAREINPUT mkhInput = new SafeNativeMethods.MOUSEKEYBDHARDWAREINPUT { mi = mi }; SafeNativeMethods.INPUT input = new SafeNativeMethods.INPUT { type = SafeNativeMethods.INPUT_TYPE.MOUSE, mkhi = mkhInput }; SafeNativeMethods.SendInput(1, ref input, Marshal.SizeOf(input)); }