private static void RecorderThread() { StringBuilder sb = new StringBuilder(4096); System.Drawing.Point pt = new System.Drawing.Point(0, 0); while (true) { bool bStartWalk = s_eventRecordNow.WaitOne(nDelayRecord); if (s_eventQuitRecording.WaitOne(0)) { break; } NativeMethods.GetPhysicalCursorPos(out pt); int dist = Math.Abs(pt.X - ptUiWalking.X) + Math.Abs(pt.Y - ptUiWalking.Y); if (bStartWalk) { // check if cursor has moved if (dist > nMinDist) { ptUiWalking.X = pt.X; ptUiWalking.Y = pt.Y; NativeMethods.GetUiXPath(ptUiWalking.X, ptUiWalking.Y, sb, sb.Capacity); if (sb.Length > 0) { string strXmlNode = sb.ToString(); int nHash = strXmlNode.GetHashCode(); if (nHash != s_nPathHash) { lock (s_lockUiPath) { MouseKeyboardEventHandler.s_strXmlNodes = $"({pt.X} {pt.Y}) " + strXmlNode; } s_nPathHash = nHash; nHoverCount = 0; if (mouseState == MouseState.LeftMouseUp) { XmlNodePathRecorder.SetUiToRootXmlNodes(ref s_strXmlNodes, true); NativeMethods.PostMessage(MainWindow.windowHandle, (uint)UiTaskName.Inspect, 0, 0); } } } } s_eventRecordNow.Reset(); } } }
public static void MouseWheel(int left, int top, short delta) { lock (MouseKeyboardEventHandler.s_lockUiPath) { if (s_strXmlNodes != null) { XmlNodePathRecorder.SetUiToRootXmlNodes(ref s_strXmlNodes); } } NativeMethods.PostMessage(MainWindow.windowHandle, (uint)UiTaskName.MouseWheel, (uint)(ConstVariables.DragDeltaOffset + delta), 0); ResetRecordTimer(); }
public static void RightMouseUp(int left, int top) { EnsureXPathReady(); PublishKeyboardInput(); if (s_strXmlNodes != null) { lock (MouseKeyboardEventHandler.s_lockUiPath) { XmlNodePathRecorder.SetUiToRootXmlNodes(ref s_strXmlNodes); NativeMethods.PostMessage(MainWindow.windowHandle, (uint)UiTaskName.RightClick, 0, 0); } } }
public static void LeftMouseUp(int left, int top) { ptCursorUp.X = left; ptCursorUp.Y = top; int dist = Math.Abs(left - ptCursorDown.X) + Math.Abs(top - ptCursorDown.Y); if (dist <= nMinDist) { //Check if it is double click if ((Environment.TickCount - tickLeftUp) < nDoubleClickDelta) { NativeMethods.PostMessage(MainWindow.windowHandle, (uint)UiTaskName.LeftDblClick, 0, 0); } else { EnsureXPathReady(); // Create a keyboard task if keys are recorded PublishKeyboardInput(); // Create a click task if (!string.IsNullOrEmpty(s_strXmlNodes)) { lock (MouseKeyboardEventHandler.s_lockUiPath) { XmlNodePathRecorder.SetUiToRootXmlNodes(ref s_strXmlNodes); NativeMethods.PostMessage(MainWindow.windowHandle, (uint)UiTaskName.LeftClick, 0, 0); } } } } else if (mouseState == MouseState.LeftMouseDrag) // drag stop - down and up are at different points { int dragDeltaX = ptCursorUp.X - ptCursorDown.X; int dragDeltaY = ptCursorUp.Y - ptCursorDown.Y; //Add DragDeltaOffset to dragDeltaX and dragDeltaY in case they are negative NativeMethods.PostMessage(MainWindow.windowHandle, (uint)UiTaskName.DragStop, (uint)(ConstVariables.DragDeltaOffset + dragDeltaX), (uint)(ConstVariables.DragDeltaOffset + dragDeltaY)); } else { //log error } tickLeftUp = Environment.TickCount; mouseState = MouseState.LeftMouseUp; }
public static void MouseMove(int left, int top) { ResetRecordTimer(); int dist = Math.Abs(left - ptUiWalking.X) + Math.Abs(top - ptUiWalking.Y); int moveDelta = Math.Abs(left - ptCursorMove.X) + Math.Abs(top - ptCursorMove.Y); ptCursorMove.X = left; ptCursorMove.Y = top; if (mouseState == MouseState.LeftMouseUp) { if (dist > nMinDist) { if ((Environment.TickCount - s_keyboardInputTick) > 2000) { PublishKeyboardInput(); } } if (moveDelta < 2 && string.IsNullOrEmpty(s_strXmlNodes) == false) { nHoverCount++; } if (nHoverCount > nMinDist) { nHoverCount = 0; XmlNodePathRecorder.SetUiToRootXmlNodes(ref s_strXmlNodes, false); NativeMethods.PostMessage(MainWindow.windowHandle, (uint)UiTaskName.MouseHover, 0, 0); } } else if (mouseState == MouseState.LeftMouseDown) // drag start - down and up are at different points { if (dist > nMinDist) { mouseState = MouseState.LeftMouseDrag; PublishKeyboardInput(); if (s_strXmlNodes != null) { lock (s_lockUiPath) { XmlNodePathRecorder.SetUiToRootXmlNodes(ref s_strXmlNodes); NativeMethods.PostMessage(MainWindow.windowHandle, (uint)UiTaskName.Drag, 0, 0); } } ptCursorDown.X = left; ptCursorDown.Y = top; } } else if (mouseState == MouseState.LeftMouseDrag) { } else { //log error } }