public static void MouseWheel(int left, int top, short delta) { lock (MouseKeyboardEventHandler.s_lockUiPath) { XmlNodePathRecorder.HandleUiEvent(ref s_strXmlNodes, EnumUiTaskName.MouseWheel, (int)delta, 0); s_strXmlNodes = null; } ResetRecordTimer(); }
public static void RightMouseUp(int left, int top) { lock (MouseKeyboardEventHandler.s_lockUiPath) { if (s_strXmlNodes != null) { XmlNodePathRecorder.HandleUiEvent(ref s_strXmlNodes, EnumUiTaskName.RightClick, 0, 0); } } }
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; }
static int PublishKeyboardInput() { if (s_listRecordedKeycode.Count == 0) { return(0); } string strBase64 = Convert.ToBase64String(s_listRecordedKeycode.ToArray()); s_listRecordedKeycode.Clear(); XmlNodePathRecorder.SetBase64KeyboardInput(strBase64, s_bCapsLock, s_bNumLock, s_bScrollLock); NativeMethods.PostMessage(MainWindow.windowHandle, (uint)UiTaskName.KeyboardInput, (uint)s_keyboardInputTick, 0); return(strBase64.Length); }
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 && (Environment.TickCount - tickLeftUp) > 1) { lock (s_lockUiPath) { XmlNodePathRecorder.HandleUiEvent(ref s_strXmlNodes, EnumUiTaskName.LeftDblClick, 0, 0); } } else { // Create a click task lock (s_lockUiPath) { if (!string.IsNullOrEmpty(s_strXmlNodes)) { XmlNodePathRecorder.HandleUiEvent(ref s_strXmlNodes, EnumUiTaskName.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; lock (s_lockUiPath) { XmlNodePathRecorder.HandleUiEvent(ref s_strXmlNodes, EnumUiTaskName.DragStop, dragDeltaX, dragDeltaY); } } tickLeftUp = Environment.TickCount; mouseState = MouseState.LeftMouseUp; }
static void PublishKeyboardInput() { string strBase64 = string.Empty; lock (s_lockUiPath) { if (s_listRecordedKeycode.Count == 0) { return; } strBase64 = Convert.ToBase64String(s_listRecordedKeycode.ToArray()); s_listRecordedKeycode.Clear(); if (string.IsNullOrEmpty(strBase64) == false) { XmlNodePathRecorder.AddKeyboardInputTask(ref strBase64, s_bCapsLock, s_bNumLock, s_bScrollLock); } } }
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 } }
private static void RecorderThread() { StringBuilder sb = new StringBuilder(NativeMethods.BUFFERSIZE); System.Drawing.Point pt = new System.Drawing.Point(0, 0); while (true) { bool bStartWalk = s_eventRecordNow.WaitOne(nDelayRecord); PublishKeyboardInput(); 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 && MouseKeyboardHook.s_bPauseMouseKeyboard == false) { // check if cursor has moved if (dist > nMinDist) { NativeMethods.PostMessage(MainWindow.s_windowHandle, (int)MainWindow.UiThreadTask.Active, 0, 0); ptUiWalking.X = pt.X; ptUiWalking.Y = pt.Y; var tick = Environment.TickCount; NativeMethods.GetUiXPath(ptUiWalking.X, ptUiWalking.Y, sb, sb.Capacity); AppInsights.LogMetric("GetUiXPathPerf", Environment.TickCount - tick); if (MouseKeyboardHook.s_bPauseMouseKeyboard == true) { continue; } if (s_eventQuitRecording.WaitOne(0)) { break; } string strXmlNode = sb.ToString(); if (!string.IsNullOrEmpty(strXmlNode)) { int nHash = strXmlNode.GetHashCode(); if (nHash != s_nPathHash) { lock (s_lockUiPath) { MouseKeyboardEventHandler.s_strXmlNodes = strXmlNode; s_nPathHash = nHash; } XmlNodePathRecorder.HandleUiEvent(ref s_strXmlNodes, EnumUiTaskName.Inspect, 0, 0); } } } s_eventRecordNow.Reset(); } } }