예제 #1
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);
            }
        }
예제 #2
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);
            }
        }