Пример #1
0
        private void StartVMMonitor_Click(object sender, EventArgs e)
        {
            //register for events
            if (Monitor.SelectedIndex == 0)
            {
                //register for mouse monitoring
                uiSystemEvents.OnUiMouse += new IUiEvents_OnUiMouseEventHandler(UiSystemEvents_OnUiMouseEvent);
                UiMouseButton msBtn     = (UiMouseButton)BTN_Combo.SelectedIndex;
                UiKeyModifier kModif    = (UiKeyModifier)KeyModifier_Combo.SelectedIndex;
                UiEventMode   eventMode = (UiEventMode)Blocking_Combo.SelectedIndex;
                uiSystemEvents.MonitorClick(msBtn, kModif, eventMode);
            }
            else
            {
                //register for hotkey monitoring
                uiSystemEvents.OnUiKeyboard += new IUiEvents_OnUiKeyboardEventHandler(UiSystemEvents_OnUiKeyboardEvent);
                string key = KeyTextBox.Text;
                if (key == "")
                {
                    key = SpecialKey_Combo.SelectedItem.ToString();
                }

                uiSystemEvents.MonitorHotkey(key, (UiKeyModifier)KeyModifier_Combo.SelectedIndex);
            }
            StartVMMonitor.Enabled = false;
        }
Пример #2
0
        private void ClickImage(UiRegion[] regionCollection, bool hover)
        {
            UiClickType   clickType   = UiClickType.UI_CLICK_SINGLE;
            UiMouseButton mouseBtn    = UiMouseButton.UI_BTN_LEFT;
            UiInputMethod inputMethod = UiInputMethod.UI_HARDWARE_EVENTS;

            //get input parameters
            if (DoubleBtn.Checked)
            {
                clickType = UiClickType.UI_CLICK_DOUBLE;
            }

            if (MiddleMouseBtn.Checked)
            {
                mouseBtn = UiMouseButton.UI_BTN_MIDDLE;
            }
            if (RightMouseBtn.Checked)
            {
                mouseBtn = UiMouseButton.UI_BTN_RIGHT;
            }

            if (Win32MsgBtn.Checked)
            {
                inputMethod = UiInputMethod.UI_WIN32_MSG;
            }
            if (ControlAPIBtn.Checked)
            {
                MessageBox.Show("Please select another input method for click or hover image");
                return;
            }

            try
            {
                if (regionCollection == null)
                {
                    if (!FindImage())
                    {
                        MessageBox.Show("The image was not found");
                        return;
                    }
                }
                if (hover)
                {
                    uiNode.Hover(uiNode.clippingRegion.width / 2, uiNode.clippingRegion.height / 2, inputMethod, 500);
                }
                else
                {
                    //click image
                    if (regionCollection == null)
                    {
                        uiNode.Click(uiNode.clippingRegion.width / 2, uiNode.clippingRegion.height / 2, clickType, mouseBtn, inputMethod);
                    }
                    else
                    {
                        //click all images
                        foreach (UiRegion region in regionCollection)
                        {
                            uiNode.clippingRegion = region;
                            uiNode.Click(uiNode.clippingRegion.width / 2, uiNode.clippingRegion.height / 2, clickType, mouseBtn, inputMethod);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #3
0
        private void TestBtn_Click(object sender, EventArgs e)
        {
            if (uiNode == null)
            {
                try
                {
                    //first select a control
                    SelectCtrlBtn_Click(null, null);
                    if (!uiNode.IsValid())
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }

            //get wait for ready level
            UiWaitForReadyLevels wfrLevel = UiWaitForReadyLevels.UI_WFR_INTERACTIVE;

            if (NoneBtn.Checked)
            {
                wfrLevel = UiWaitForReadyLevels.UI_WFR_NONE;
            }
            if (CompleteBtn.Checked)
            {
                wfrLevel = UiWaitForReadyLevels.UI_WFR_COMPLETE;
            }

            //get input method
            UiInputMethod inputMethod = UiInputMethod.UI_HARDWARE_EVENTS;

            if (CtrlAPIBtn.Checked)
            {
                inputMethod = UiInputMethod.UI_CONTROL_API;
            }
            if (Win32Msg.Checked)
            {
                inputMethod = UiInputMethod.UI_WIN32_MSG;
            }
            try
            {
                //get control position
                UiRegion position = (UiRegion)uiNode.Get("position");

                //set offsets to the center of the control
                int offsetX = position.width / 2;
                int offsetY = position.height / 2;

                //set wait for ready level
                uiNode.waitForReadyLevel = wfrLevel;

                if (HoverOnlyBtn.Checked)
                {
                    //hover control
                    uiNode.Hover(offsetX, offsetY, inputMethod, 500);
                }
                else
                {
                    //click control
                    //get mouse button
                    UiMouseButton mouseBtn = UiMouseButton.UI_BTN_LEFT;
                    if (RightMouseBtn.Checked)
                    {
                        mouseBtn = UiMouseButton.UI_BTN_RIGHT;
                    }
                    if (MiddleMouseBtn.Checked)
                    {
                        mouseBtn = UiMouseButton.UI_BTN_MIDDLE;
                    }

                    //get click type
                    UiClickType clickType = UiClickType.UI_CLICK_SINGLE;
                    if (DoubleButton.Checked)
                    {
                        clickType = UiClickType.UI_CLICK_DOUBLE;
                    }

                    uiNode.Click(offsetX, offsetY, clickType, mouseBtn, inputMethod);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }