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();
        }
        public IControl Assign(System.Windows.Automation.AutomationElement element, ControlType controlType, ActionType actionType, string Criteria)
        {
            IControl x = Produce(controlType, actionType, Criteria);

            x.Assign(element);
            return(x);
        }
Example #3
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            // Enables WPF to mark edit field as supporting text pattern (Automation Concept)
            System.Windows.Automation.AutomationElement asForm =
                System.Windows.Automation.AutomationElement.FromHandle(new WindowInteropHelper(this).Handle);

            // Windows 8 API to enable touch keyboard to monitor for focus tracking in this WPF application
            InputPanelConfigurationLib.InputPanelConfiguration inputPanelConfig = new InputPanelConfigurationLib.InputPanelConfiguration();
            inputPanelConfig.EnableFocusTracking();
        }
        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;

                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
                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)
                {
                    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)
            {
                this.Close();
            }
        }
Example #5
0
        /// <summary>
        /// 指定したウィンドウハンドルの親を探す。(同じプロセスIDで一番上のAutomationElement)
        /// </summary>
        /// <param name="el"></param>
        /// <returns></returns>
        System.Windows.Automation.AutomationElement TopElement(System.Windows.Automation.AutomationElement el)
        {
            if (el == null)
            {
                return(null);
            }

            System.Windows.Automation.AutomationElement p = tw.GetParent(el);
            if (p == null)
            {
                return(el); //親は無い
            }
            if (p.Current.ProcessId == el.Current.ProcessId)
            {
                return(TopElement(p));
            }

            return(el);
        }
Example #6
0
        /// <summary>
        /// キャプチャ(ウィンドウ)
        /// </summary>
        /// <param name="el"></param>
        /// <param name="path"></param>
        void Cpt(System.Windows.Automation.AutomationElement el, string path)
        {
            if (el == null)
            {
                return;
            }

            if (el.Current.NativeWindowHandle != 0)
            {
                System.Drawing.Bitmap bmp = CaptureHelper.CaptureWindow((IntPtr)el.Current.NativeWindowHandle);
                bmp.Save(path, System.Drawing.Imaging.ImageFormat.Png);
            }

            /*
             * string name = el.Current.ControlType.LocalizedControlType;
             * string type = el.Current.ItemType;
             * string hnd = el.Current.NativeWindowHandle.ToString();
             * string pid = el.Current.ProcessId.ToString();
             */
        }
Example #7
0
        /// <summary>
        /// To find TreeGridStackedHeaderCell.
        /// </summary>
        public override void Find()
        {
            //create UITestControl from current instance
            UITestControl control = new UITestControl();

            control.CopyFrom(this);
            //get the search properties from grid cell instance
            var properties = control.SearchProperties.ToList();

            var headerCellProperties = new List <string>();

            headerCellProperties.Add("ColumnName");

            bool isContainProperty = false;

            foreach (var property in properties)
            {
                if (headerCellProperties.Contains(property.PropertyName))
                {
                    isContainProperty = true;
                    break;
                }
            }

            if (isContainProperty)
            {
                // throw exception if properties are not enough to search a control
                if (properties.Count < 1 || properties.Where(p => p.PropertyName == "ColumnName").Count() < 1)
                {
                    throw new UITestException("Not Enough Properties to find a control");
                }

                // get the collection of child elements from  SfTreeGrid container
                UITestControlCollection rowCollection = control.Container.GetChildren();
                //bool flag = false;
                foreach (UITestControl row in rowCollection)
                {
                    if (row.ClassName == "Uia.TreeGridHeaderRowControl")
                    {
                        UITestControlCollection collection = row.GetChildren();

                        foreach (UITestControl child in collection)
                        {
                            // check child is treegrid stackedHeaderCell
                            if (child.ClassName == "Uia.TreeGridStackedHeaderCell")
                            {
                                Dictionary <string, string> childPropertiesDictonary          = new Dictionary <string, string>();
                                System.Windows.Automation.AutomationElement automationElement = child.NativeElement as System.Windows.Automation.AutomationElement;
                                if (automationElement == null)
                                {
                                    continue;
                                }
                                System.Windows.Automation.AutomationElement.AutomationElementInformation current2 = automationElement.Current;
                                string[] array = current2.ItemStatus.Split(new string[]
                                {
                                    "#"
                                }, StringSplitOptions.None);

                                // assign the properties values to corresponding variable for condition checking
                                childPropertiesDictonary.Add("ColumnName", array[0]);

                                // set flag to true if  all property values are match to  child control
                                foreach (var item in properties)
                                {
                                    if (childPropertiesDictonary.Keys.Contains(item.PropertyName))
                                    {
                                        if (childPropertiesDictonary[item.PropertyName] == item.PropertyValue)
                                        {
                                            isFound = true;
                                        }
                                        else
                                        {
                                            isFound = false;
                                            break;
                                        }
                                    }
                                }

                                // here this condition check is  used  for finding exact gridcell from its given proerty values
                                if (isFound)
                                {
                                    //set the  corresponding cell values to its properties.
                                    this.columnName = array[0];

                                    // copy the  found cell as this  instance
                                    this.CopyFrom(child);

                                    childPropertiesDictonary = null;
                                    break;
                                }
                            }
                        }
                        if (isFound)
                        {
                            break;
                        }
                    }
                }
                if (!isFound)
                {
                    throw new UITestException("Not Maching control for this sepecific property");
                }
            }
            else
            {
                base.Find();
                System.Windows.Automation.AutomationElement automationElement = this.NativeElement as System.Windows.Automation.AutomationElement;
                if (automationElement == null)
                {
                    throw new UITestException("Not Maching control for this sepecific property");
                }
                System.Windows.Automation.AutomationElement.AutomationElementInformation current2 = automationElement.Current;
                string[] array = current2.ItemStatus.Split(new string[]
                {
                    "#"
                }, StringSplitOptions.None);
                if (array.Count() != 0)
                {
                    this.columnName = array[0];
                }
                else
                {
                    throw new UITestException("Not Maching control for this sepecific property");
                }
            }
        }
Example #8
0
        void DoCapture(object param)
        {
            MouseMessage mouse = (MouseMessage)param;

            if (_captureList.Count > 100)
            {
                return; //ファイル数制限をつけておく
            }
            System.Windows.Point point = new Point(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y);
            System.Windows.Automation.AutomationElement el = null;

            try
            {
                el = System.Windows.Automation.AutomationElement.FromPoint(point);

                if (el == null)
                {
                    return;
                }

                if (el.Current.ProcessId == System.Diagnostics.Process.GetCurrentProcess().Id)
                {
                    return; //自分自身のWindow上のクリックは無視
                }
                string path_w = System.IO.Path.Combine(setting.SaveDir, DateTime.Now.ToString("HHmmssfff") + "-w.png");
                string path_c = System.IO.Path.Combine(setting.SaveDir, DateTime.Now.ToString("HHmmssfff") + "-c.png");

                System.Windows.Automation.AutomationElement el_top = TopElement(el);

                CaptureEntry entry = new CaptureEntry();
                entry.MouseMessage        = mouse;
                entry.ClickedControlType  = el.Current.LocalizedControlType;
                entry.ClickedName         = el.Current.Name;
                entry.ClickedRect         = el.Current.BoundingRectangle;
                entry.ClickedWindowHandle = el.Current.NativeWindowHandle;
                entry.Cursor            = point;
                entry.PathToWindowImage = path_w;
                entry.PathToClipImage   = path_c;

                if (el_top != null)
                {
                    entry.WindowControlType = el_top.Current.LocalizedControlType;
                    entry.WindowName        = el_top.Current.Name;
                    entry.WindowRect        = el_top.Current.BoundingRectangle;
                    entry.WindowHandle      = el_top.Current.NativeWindowHandle;
                }

                //キャプチャ
                //Cpt(el_top, path_w);
                Cpt(point, path_c, path_w, entry);

                this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate
                {
                    //リストに追加
                    entry.No            = _captureList.Count + 1;
                    entry.SelectedIndex = setting.InitialImage;
                    _captureList.Add(entry);
                    listView1.SelectedIndex = (_captureList.Count - 1);

                    //スクロール位置と画像表示
                    this.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate
                    {
                        listView1.ScrollIntoView(entry);
                        if (entry.SelectedIndex == 1)
                        {
                            image1.Source = entry.ClipImage;
                        }
                        else
                        {
                            image1.Source = entry.WindowImage;
                        }
                    }));
                }));
            }
            catch (System.Windows.Automation.ElementNotAvailableException)
            {
                //無視
            }
            catch (Exception ex)
            {
                this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate
                {
                    MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
                }));
            }
        }
 public SnapshotCategoriesList(System.Windows.Automation.AutomationElement element)
 {
 }
 public MessageBoxMap(System.Windows.Automation.AutomationElement element)
 {
 }
 public SnapshotsViewMap(System.Windows.Automation.AutomationElement element)
 {
 }
 public SnapshotWindow(System.Windows.Automation.AutomationElement element)
 {
 }