private static void OnMouseDown(InputEventArgs e) { try { if (SAPHook.Instance.Connections.Count() == 0) { return; } if (SAPHook.Instance.UIElements.Count() == 0) { return; } var Element = System.Windows.Automation.AutomationElement.FromPoint(new System.Windows.Point(e.X, e.Y)); if (Element != null) { var ProcessId = Element.Current.ProcessId; if (ProcessId < 1) { return; } if (SAPProcessId > 0 && SAPProcessId != ProcessId) { return; } if (SAPProcessId != ProcessId) { var p = System.Diagnostics.Process.GetProcessById(ProcessId); if (p.ProcessName.ToLower() == "saplogon") { SAPProcessId = p.Id; } if (p.ProcessName.ToLower() != "saplogon") { return; } } LastElement = Element; SAPEventElement[] elements = new SAPEventElement[] { }; lock (SAPHook.Instance.UIElements) { elements = SAPHook.Instance.UIElements.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray(); } if (elements.Count() > 0) { var last = elements.OrderBy(x => x.Id.Length).Last(); SAPEvent message = new SAPEvent("mousedown"); message.Set(last); form.AddText("[send] " + message.action + " " + last.Id); pipe.PushMessage(message); } else { log("OnMouseDown " + e.X + "," + e.Y + " not found in UI List"); } } } catch (Exception) { } }
private static void OnMouseMove(InputEventArgs e) { lock (_lock) { if (isMoving) { return; } isMoving = true; } try { if (SAPHook.Instance.Connections.Count() == 0 || SAPHook.Instance.UIElements.Count() == 0) { lock (_lock) { isMoving = false; } return; } var Element = System.Windows.Automation.AutomationElement.FromPoint(new System.Windows.Point(e.X, e.Y)); if (Element != null) { var ProcessId = Element.Current.ProcessId; if (ProcessId < 1) { lock (_lock) { isMoving = false; } return; } if (SAPProcessId > 0 && SAPProcessId != ProcessId) { lock (_lock) { isMoving = false; } return; } if (SAPProcessId != ProcessId) { var p = System.Diagnostics.Process.GetProcessById(ProcessId); if (p.ProcessName.ToLower() == "saplogon") { SAPProcessId = p.Id; } if (p.ProcessName.ToLower() != "saplogon") { lock (_lock) { isMoving = false; } return; } } if (SAPHook.Instance.Connections.Count() == 0) { SAPHook.Instance.RefreshSessions(); } if (SAPHook.Instance.UIElements.Count() == 0) { SAPHook.Instance.RefreshUIElements(true); } SAPEventElement[] elements = new SAPEventElement[] { }; lock (SAPHook.Instance.UIElements) { elements = SAPHook.Instance.UIElements.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray(); } if (elements.Count() > 0) { //Program.log("[mousemove] " + e.X + " " + e.Y); //foreach(var ele in elements) //{ // Program.log("[element] " + ele.ToString()); //} var found = elements.OrderBy(x => x.IdPathCell.Length).Last(); if (found.Items != null && found.Items.Length > 0) { elements = found.Items.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray(); if (elements != null && elements.Length > 0) { found = elements.OrderBy(x => x.IdPathCell.Length).Last(); } } //Program.log("[element] " + found.ToString() + " " + found.Rectangle.ToString()); if (found.Items != null && found.Items.Length > 0) { var found2 = found.Items.Where(x => x.Rectangle.Contains(e.X, e.Y)).ToArray(); if (found2.Length > 0) { found = found2.First(); } } if (LastElement != null && (found.Id == LastElement.Id && found.Path == LastElement.Path && found.Cell == LastElement.Cell)) { // form.AddText("[SKIP] mousemove " + LastElement.ToString()); lock (_lock) { isMoving = false; } return; } LastElement = found; SAPEvent message = new SAPEvent("mousemove"); message.Set(LastElement); form.AddText("[send] " + message.action + " " + LastElement.ToString() + " " + LastElement.Rectangle.ToString()); pipe.PushMessage(message); } else { log("Mouseover " + e.X + "," + e.Y + " not found in UI List"); } } } catch (Exception) { } lock (_lock) { isMoving = false; } }