예제 #1
0
        // EXAMPLE CODE SECTION
        private void mouseHook_MouseEvent(Kennedy.ManagedHooks.MouseEvents mEvent, Point point, IntPtr hwnd)
        {
            System.Windows.Point wpt = new System.Windows.Point(point.X, point.Y);

            try
            {
                AutomationElement autoElem = AutomationElement.FromPoint(wpt);
                //autoElem.SetFocus();
                //AutomationElement autoElem = AutomationElement.FocusedElement;
                if (autoElem == null)
                {
                    AddText("Automation null");
                }
                string name = "[" + autoElem.Current.Name;
                object controlTypeNoDefault = autoElem.GetCurrentPropertyValue(AutomationElement.ControlTypeProperty, true);
                if (controlTypeNoDefault != AutomationElement.NotSupported)
                {
                    ControlType controlType = controlTypeNoDefault as ControlType;
                    name += "] [" + controlType.LocalizedControlType + "]";
                }
                //string name = "null";
                string msg = string.Format("Mouse event: {0}-->{1}: ({2},{3}).,{4}", mEvent.ToString(), name, point.X, point.Y, hwnd);
                AddText(msg);
            }
            catch (System.Exception ex)
            {
                AutomationElement targetElem = null;

                targetElem = GetElementsByPoint(point);
                if (targetElem == null)
                {
                    AddText("get element error");
                }
                string name = "[" + targetElem.Cached.Name;
                object controlTypeNoDefault = targetElem.GetCachedPropertyValue(AutomationElement.ControlTypeProperty, true);
                if (controlTypeNoDefault != AutomationElement.NotSupported)
                {
                    ControlType controlType = controlTypeNoDefault as ControlType;
                    name += "] [" + controlType.LocalizedControlType + "]";
                }
                string msg = string.Format("Mouse event: {0}-->{1}: ({2},{3}).,{4}", mEvent.ToString(), name, point.X, point.Y, hwnd);
                AddText(msg);
            }
        }
예제 #2
0
        // EXAMPLE CODE SECTION
        private void mouseHook_MouseEvent(Kennedy.ManagedHooks.MouseEvents mEvent, Point point)
        {
            string msg = string.Format("Mouse event: {0}: ({1},{2}).", mEvent.ToString(), point.X, point.Y);

            AddText(msg);
        }