public static void HandleUiEvent(ref string strXml, EnumUiTaskName uiTaskName, int deltaX, int deltaY) { List <string> nodesRootToLeaf = null; if (uiTaskName == EnumUiTaskName.Inspect) { nodesRootToLeaf = GetRootToLeafNodes(strXml); if (nodesRootToLeaf != null && nodesRootToLeaf.Count > 0) { MainWindow.AddInspectUi(new RecordedUiTask(nodesRootToLeaf, uiTaskName)); } return; } if (uiTaskName != EnumUiTaskName.KeyboardInput) { nodesRootToLeaf = GetRootToLeafNodes(strXml); strXml = null; } RecordedUiTask lastRecordedUi = null; lock (RecordedUiTask.s_lockRecordedUi) { if (RecordedUiTask.s_listRecordedUi.Count > 0) { lastRecordedUi = RecordedUiTask.s_listRecordedUi.Last(); } } bool bAddNewTask = true; // Completing last UI if (uiTaskName == EnumUiTaskName.LeftDblClick && lastRecordedUi != null) { lastRecordedUi.ChangeClickToDoubleClick(); bAddNewTask = false; } else if (uiTaskName == EnumUiTaskName.MouseWheel) { if (lastRecordedUi == null || lastRecordedUi.UiTaskName != EnumUiTaskName.MouseWheel) { if (nodesRootToLeaf != null && nodesRootToLeaf.Count > 0) { lastRecordedUi = new RecordedUiTask(nodesRootToLeaf, uiTaskName); MainWindow.AddRecordedUi(lastRecordedUi); } } if (lastRecordedUi != null && lastRecordedUi.UiTaskName == EnumUiTaskName.MouseWheel) { lastRecordedUi.UpdateWheelData(deltaX); } bAddNewTask = false; } if (bAddNewTask) { if (nodesRootToLeaf != null && nodesRootToLeaf.Count > 0) { MainWindow.AddRecordedUi(new RecordedUiTask(nodesRootToLeaf, uiTaskName)); } } else if (lastRecordedUi != null) { //MouseWheel, DoubleClick MainWindow.UpdateLastUi(lastRecordedUi); } NativeMethods.PostMessage(MainWindow.s_windowHandle, (int)MainWindow.UiThreadTask.ActionAdded, 0, 0); AppInsights.LogEvent("HandleUiEvent", uiTaskName.ToString()); }
public static IntPtr ProcessMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { handled = false; string left, top; if (msg == (int)UiTaskName.Inspect) { var nodesRootToLeaf = GetRootToLeafNodes(strUiToRootXmlNodesInspect, out left, out top); if (nodesRootToLeaf != null) { string strXmlNodes = CreateUiTaskXmlNodeString(nodesRootToLeaf, ((UiTaskName)msg).ToString(), left, top); if (string.IsNullOrEmpty(strXmlNodes) == false) { MainWindow.AddRecordedUi(new RecordedUiTask(strXmlNodes, 0, (UiTaskName)msg)); } } return(IntPtr.Zero); } if (MainWindow.IsRecording() == false) { return(IntPtr.Zero); } lock (lockUiPath) { if (msg == (int)UiTaskName.KeyboardInput) { var keyboardTaskDescription = GenerateCSCode.GetDecodedKeyboardInput(strBase64KeyboardInput, bCapsLock, bNumLock, bScrollLock); StringBuilder sb = new StringBuilder(); foreach (var strLine in keyboardTaskDescription) { sb.Append(GenerateXPath.XmlEncode(strLine)); } var keyboarTask = new RecordedUiTask($"<UiTask task=\"{UiTaskName.KeyboardInput}\" VirtualKeys=\"{sb.ToString()}\" base64String=\"{strBase64KeyboardInput}\" CapsLock=\"{bCapsLock}\" NumLock=\"{bNumLock}\" ScrollLock=\"{bScrollLock}\"/>\n", (int)wParam, (UiTaskName)msg); MainWindow.AddRecordedUi(keyboarTask); } else if ((int)UiTaskName.LeftClick <= msg && msg <= (int)UiTaskName.MouseHover) { RecordedUiTask lastRecordedUi = null; if (MainWindow.s_listRecordedUi.Count > 0) { lastRecordedUi = MainWindow.s_listRecordedUi.Last(); } string strXmlNodes = null; List <string> nodesRootToLeaf = GetRootToLeafNodes(strUiToRootXmlNodes, out left, out top); if (nodesRootToLeaf != null && nodesRootToLeaf.Count > 1) { strXmlNodes = CreateUiTaskXmlNodeString(nodesRootToLeaf, ((UiTaskName)msg).ToString(), left, top); } bool bAddNewTask = true; // Completing last UI if (msg == (int)UiTaskName.LeftDblClick && lastRecordedUi != null) { lastRecordedUi.ChangeClickToDoubleClick(); bAddNewTask = false; } else if (msg == (int)UiTaskName.DragStop && lastRecordedUi != null) { int deltaX = wParam.ToInt32() - ConstVariables.DragDeltaOffset; int deltaY = lParam.ToInt32() - ConstVariables.DragDeltaOffset; lastRecordedUi.DragComplete(deltaX, deltaY); bAddNewTask = false; } else if (msg == (int)UiTaskName.MouseWheel) { int delta = wParam.ToInt32() - ConstVariables.DragDeltaOffset; if (strXmlNodes != null) { if (lastRecordedUi == null || lastRecordedUi.GetTask() != UiTaskName.MouseWheel) { lastRecordedUi = new RecordedUiTask(strXmlNodes, 0, (UiTaskName)msg); MainWindow.AddRecordedUi(lastRecordedUi); } } if (lastRecordedUi != null && lastRecordedUi.GetTask() == UiTaskName.MouseWheel) { lastRecordedUi.UpdateWheelData(delta); } bAddNewTask = false; } // Adding newly recorded UI if (bAddNewTask) { MainWindow.AddRecordedUi(new RecordedUiTask(strXmlNodes, 0, (UiTaskName)msg)); } else { MainWindow.UpdateLastUi(lastRecordedUi); } } return(IntPtr.Zero); } }