private static MOUSEEVENTF MouseActionToMouseEvent(RemoteDesktopMouseAction mouseAction, ref int mouseData) { switch (mouseAction) { case RemoteDesktopMouseAction.LeftDown: return(MOUSEEVENTF.LEFTDOWN); case RemoteDesktopMouseAction.LeftUp: return(MOUSEEVENTF.LEFTUP); case RemoteDesktopMouseAction.RightDown: return(MOUSEEVENTF.RIGHTDOWN); case RemoteDesktopMouseAction.RightUp: return(MOUSEEVENTF.RIGHTUP); case RemoteDesktopMouseAction.MiddleDown: return(MOUSEEVENTF.MIDDLEDOWN); case RemoteDesktopMouseAction.MiddleUp: return(MOUSEEVENTF.MIDDLEUP); case RemoteDesktopMouseAction.XButton1Down: mouseData = XBUTTON1; return(MOUSEEVENTF.XDOWN); case RemoteDesktopMouseAction.XButton1Up: mouseData = XBUTTON1; return(MOUSEEVENTF.XUP); case RemoteDesktopMouseAction.XButton2Down: mouseData = XBUTTON2; return(MOUSEEVENTF.XDOWN); case RemoteDesktopMouseAction.XButton2Up: mouseData = XBUTTON2; return(MOUSEEVENTF.XUP); case RemoteDesktopMouseAction.Move: return(MOUSEEVENTF.MOVE); case RemoteDesktopMouseAction.Wheel: return(MOUSEEVENTF.WHEEL); default: throw new ArgumentOutOfRangeException(nameof(mouseAction), mouseAction, null); } }
public void DoMouseAction(RemoteDesktopMouseAction mouseAction, int x, int y, int extraData, int monitor) { var screen = _screens[monitor]; x = screen.Bounds.X + x; y = screen.Bounds.Y + y; INPUT mouseDownInput = new INPUT(); mouseDownInput.type = InputType.MOUSE; mouseDownInput.U.mi.dwFlags = MouseActionToMouseEvent(mouseAction, ref extraData) | MOUSEEVENTF.ABSOLUTE | MOUSEEVENTF.VIRTUALDESK | MOUSEEVENTF.MOVE; mouseDownInput.U.mi.dx = CalculateAbsoluteCoordinateX(x); mouseDownInput.U.mi.dy = CalculateAbsoluteCoordinateY(y); mouseDownInput.U.mi.mouseData = extraData; SendIput(mouseDownInput); }
public void DoMouseAction(RemoteDesktopMouseAction mouseAction, int x, int y, int extra, long windowHandle) { Desktop.SetCurrent(Desktop); Desktop.DesktopActions.DoMouseAction(mouseAction, x, y, extra, windowHandle); }
public void DoMouseAction(RemoteDesktopMouseAction mouseAction, int x, int y, int extra, long windowHandle) { var handle = (IntPtr)windowHandle; var windowinfo = new WINDOWINFO(true); NativeMethods.GetWindowInfo(handle, ref windowinfo); RECT windowRect; NativeMethods.GetWindowRect(handle, out windowRect); var screenX = windowRect.X + x; var screenY = windowRect.Y + y; var hitTest = HitTestValues.HTNOWHERE; var window = WindowFromPoint(new Point(screenX, screenY), 100, ref hitTest, IntPtr.Zero); if (hitTest >= HitTestValues.HTSIZEFIRST && hitTest <= HitTestValues.HTSIZELAST) { var style = (WindowStyles)GetWindowLong(window, GWL_STYLE); if ((style & WindowStyles.WS_CHILD) == WindowStyles.WS_CHILD && !StyleHaveSizeBorders(style)) { var parent = GetParent(window); if (parent != IntPtr.Zero) { window = parent; } } } if ((GetWindowClassFlags(window) & WindowPrintTypes.WCF_MOUSE_AUTOCAPTURE) != 0) { hitTest = HitTestValues.HTCLIENT; } if (window == IntPtr.Zero) { return; } var info = new WINDOWINFO(); info.cbSize = (uint)Marshal.SizeOf(info); if (!NativeMethods.GetWindowInfo(window, ref info)) { return; } var screenCursorPos = MAKELPARAM(screenX, screenY); IntPtr clientCursorPos; //if (hitTest == HitTestValues.HTCLIENT) // { if ((GetWindowClassFlags(window) & WindowPrintTypes.WCF_MOUSE_CLIENT_TO_SCREEN) == WindowPrintTypes.WCF_MOUSE_CLIENT_TO_SCREEN) { clientCursorPos = screenCursorPos; } else { clientCursorPos = MAKELPARAM(screenX - info.rcClient.Left, screenY - info.rcClient.Top); } WM windowMessage; WM ncWindowMessage; switch (mouseAction) { case RemoteDesktopMouseAction.LeftDown: windowMessage = WM.LBUTTONDOWN; ncWindowMessage = WM.NCLBUTTONDOWN; break; case RemoteDesktopMouseAction.LeftUp: windowMessage = WM.LBUTTONUP; ncWindowMessage = WM.NCLBUTTONUP; break; case RemoteDesktopMouseAction.RightDown: windowMessage = WM.RBUTTONDOWN; ncWindowMessage = WM.NCRBUTTONDOWN; break; case RemoteDesktopMouseAction.RightUp: windowMessage = WM.RBUTTONUP; ncWindowMessage = WM.NCRBUTTONDOWN; break; case RemoteDesktopMouseAction.MiddleDown: windowMessage = WM.MBUTTONDOWN; ncWindowMessage = WM.NCMBUTTONDOWN; break; case RemoteDesktopMouseAction.MiddleUp: windowMessage = WM.MBUTTONUP; ncWindowMessage = WM.NCMBUTTONUP; break; case RemoteDesktopMouseAction.XButton1Down: windowMessage = WM.XBUTTONDOWN; ncWindowMessage = WM.NCXBUTTONDOWN; break; case RemoteDesktopMouseAction.XButton1Up: windowMessage = WM.XBUTTONUP; ncWindowMessage = WM.NCXBUTTONUP; break; case RemoteDesktopMouseAction.XButton2Down: case RemoteDesktopMouseAction.XButton2Up: return; case RemoteDesktopMouseAction.Move: windowMessage = WM.MOUSEMOVE; ncWindowMessage = WM.NCMOUSEMOVE; break; case RemoteDesktopMouseAction.Wheel: return; default: throw new ArgumentOutOfRangeException(nameof(mouseAction), mouseAction, null); } MouseEvent(window, windowinfo, hitTest, windowMessage, ncWindowMessage, clientCursorPos, screenCursorPos); }
public void DoMouseClick(Point p, RemoteDesktopMouseAction mouseAction) { var hitTest = HitTestValues.HTNOWHERE; var window = WindowFromPoint(p, 100, ref hitTest, IntPtr.Zero); if (hitTest >= HitTestValues.HTSIZEFIRST && hitTest <= HitTestValues.HTSIZELAST) { var style = (WindowStyles)GetWindowLong(window, GWL_STYLE); if ((style & WindowStyles.WS_CHILD) == WindowStyles.WS_CHILD && !StyleHaveSizeBorders(style)) { var parent = GetParent(window); if (parent != IntPtr.Zero) { window = parent; } } } //TODO if ((GetWindowClassFlags(window) & WindowPrintTypes.WCF_MOUSE_AUTOCAPTURE) != 0) { hitTest = HitTestValues.HTCLIENT; } if (window == IntPtr.Zero) { return; } var info = new WINDOWINFO(); info.cbSize = (uint)Marshal.SizeOf(info); if (!NativeMethods.GetWindowInfo(window, ref info)) { return; } var screenCursorPos = MAKELPARAM(p.X, p.Y); IntPtr clientCursorPos; //if (hitTest == HitTestValues.HTCLIENT) // { if ((GetWindowClassFlags(window) & WindowPrintTypes.WCF_MOUSE_CLIENT_TO_SCREEN) == WindowPrintTypes.WCF_MOUSE_CLIENT_TO_SCREEN) { clientCursorPos = screenCursorPos; } else { clientCursorPos = MAKELPARAM(p.X - info.rcClient.Left, p.Y - info.rcClient.Top); } // } // else // clientCursorPos = IntPtr.Zero; if (mouseAction == RemoteDesktopMouseAction.LeftDown) { MouseEvent(window, info, hitTest, WM.LBUTTONDOWN, WM.NCLBUTTONDOWN, clientCursorPos, screenCursorPos); } if (mouseAction == RemoteDesktopMouseAction.LeftUp) { MouseEvent(window, info, hitTest, WM.LBUTTONUP, WM.NCLBUTTONUP, clientCursorPos, screenCursorPos); } //SetForegroundWindow(result.Key.Handle); /* * NativeMethods.SendMessage(handle, (uint) (isMouseDown ? (leftMouseButton ? WM.LBUTTONDOWN : WM.RBUTTONDOWN) : (leftMouseButton ? WM.LBUTTONUP : WM.RBUTTONUP)), * (IntPtr) MK_LBUTTON, * (IntPtr) ((controlY << 16) | (controlX & 0xFFFF))); * /* * NativeMethods.PostMessage(new HandleRef(null, handle), (uint) WM.LBUTTONUP, * IntPtr.Zero, * (IntPtr) ((controlY << 16) | (controlX & 0xFFFF)));*/ //if (handle != result.Key.Handle) // NativeMethods.SendMessage(result.Key.Handle, (uint) WM.PARENTNOTIFY, new IntPtr((uint) WM.LBUTTONDOWN), // MAKELPARAM(windowX, windowY)); /*NativeMethods.PostMessage(new HandleRef(null, handle), WM_LBUTTONUP, * (IntPtr) 0x1, * (IntPtr) ((y << 16) | (x & 0xFFFF)));*/ }