private void GlobalHook_MouseEvent(object sender, MouseCoordinateEventArgs e) { //mouse down has occured //invoke UIA try { System.Windows.Automation.AutomationElement element = System.Windows.Automation.AutomationElement.FromPoint(e.MouseCoordinates); System.Windows.Automation.AutomationElement.AutomationElementInformation elementProperties = element.Current; //get properties from class via reflection System.Reflection.PropertyInfo[] properties = typeof(System.Windows.Automation.AutomationElement.AutomationElementInformation).GetProperties(); Array.Sort(properties, (x, y) => String.Compare(x.Name, y.Name)); //loop through each property and get value from the element foreach (System.Reflection.PropertyInfo property in properties) { var propName = property.Name; var propValue = property.GetValue(elementProperties, null); //if property is a basic type then display if ((propValue is string) || (propValue is bool) || (propValue is int) || (propValue is double)) { searchParameters.Rows.Add(false, propName, propValue); } } } catch (Exception) { MessageBox.Show("Error in recording, please try again!"); } this.WindowState = FormWindowState.Normal; this.Close(); }
private void GlobalHook_MouseEvent(object sender, MouseCoordinateEventArgs e) { //mouse down has occured //invoke UIA try { AutomationElement element = AutomationElement.FromPoint(e.MouseCoordinates); AutomationElement.AutomationElementInformation elementProperties = element.Current; LastItemClicked = $"[Name:{element.Current.Name}].[ID:{element.Current.AutomationId.ToString()}].[Class:{element.Current.ClassName}]"; lblSubHeader.Text = LastItemClicked; SearchParameters.Rows.Clear(); //get properties from class via reflection PropertyInfo[] properties = typeof(AutomationElement.AutomationElementInformation).GetProperties(); Array.Sort(properties, (x, y) => String.Compare(x.Name, y.Name)); //loop through each property and get value from the element foreach (PropertyInfo property in properties) { try { var propName = property.Name; var propValue = property.GetValue(elementProperties, null); //if property is a basic type then display if ((propValue is string) || (propValue is bool) || (propValue is int) || (propValue is double)) { SearchParameters.Rows.Add(false, propName, propValue); } } catch (Exception ex) { MessageBox.Show("Error Iterating over properties in window: " + ex.ToString()); } } } catch (Exception) { lblDescription.Text = "Error cloning element. Please Try Again."; //MessageBox.Show("Error in recording, please try again! " + ex.ToString()); } if (chkStopOnClick.Checked) { Close(); } }
private void GlobalHook_MouseEvent(object sender, MouseCoordinateEventArgs e) { //mouse down has occured if (e != null) { //invoke UIA try { if (_isRecording) { var windowName = GetWindowName((int)e.MouseCoordinates.X, (int)e.MouseCoordinates.Y); if (WindowName != windowName && !string.IsNullOrEmpty(windowName)) { WindowName = windowName; cboWindowTitle.SelectedItem = WindowName; if (IsRecordingSequence) { BuildActivateWindowCommand(); } } LoadSearchParameters(e.MouseCoordinates); lblDescription.Text = _recordingMessage; } string clickType; switch (e.MouseMessage) { case MouseMessages.WmLButtonDown: if (e.MouseCoordinates.X == _lastClickedMouseCoordinates.X && e.MouseCoordinates.Y == _lastClickedMouseCoordinates.Y && _stopwatch.ElapsedMilliseconds <= 500) { _stopwatch.Stop(); //remove previous commands generated from single click for (int i = 0; i < 2; i++) { _sequenceCommandList.RemoveAt(_sequenceCommandList.Count - 1); } clickType = "Double Left Click"; } else { clickType = "Left Click"; } break; case MouseMessages.WmMButtonDown: clickType = "Middle Click"; break; case MouseMessages.WmRButtonDown: clickType = "Right Click"; break; default: clickType = "Left Click"; break; } if (IsRecordingSequence && _isRecording) { BuildElementClickActionCommand(clickType); } _lastClickedMouseCoordinates = e.MouseCoordinates; } catch (Exception) { lblDescription.Text = _errorMessage; } } if (chkStopOnClick.Checked) { Close(); } }