예제 #1
0
        /// <summary>
        /// Specify which control or form we should use for the relative position.
        /// </summary>
        public void UseOn(ReflectionTester control)
        {
            if (mouseControl == null)
            {
                Win32.GetCursorPos(out originalPosition);
            }

            if (control == null)
            {
                throw new ArgumentNullException(nameof(control));
            }

            mouseControl = new MouseControl(control);

            PositionUnit = GraphicsUnit.Pixel;

            // Block any user input while we are active.
            if (!restoreUserInput)
            {
                if (!Win32.BlockInput(true))
                {
                    //throw new Win32Exception();
                }

                restoreUserInput = true;
            }
        }
예제 #2
0
        /// <summary>
        /// Specify which control or form we should use for the relative position.
        /// </summary>
        /// <param name="control">
        ///   A <see cref="ControlTester"/>.
        /// </param>
        public void UseOn(ControlTester control)
        {
            if (mouseControl == null)
            {
                Win32.Point position;
                Win32.GetCursorPos(out position);
                originalPosition = new Point(position.x, position.y);
            }

            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            mouseControl = new MouseControl(control);

            PositionUnit = GraphicsUnit.Pixel;

            // Block any user input while we are active.
            if (!restoreUserInput)
            {
                if (!Win32.BlockInput(true))
                {
                    //TODO Bart De Boeck : Waarom is dit nodig ? Zie ook in Dispose().
                    //throw new Win32Exception();
                }

                restoreUserInput = true;
            }
        }
예제 #3
0
 /// <summary>
 /// Implements the IDisposable interface.  This restores user input.
 /// It should eventually return the keyboard to its pre-test state.
 /// </summary>
 /// <remarks>
 /// If you are using the Keyboard controller through the base NUnitFormTest
 /// class, then you should not need to call this method or use finally or using
 /// blocks.  The base class handles this for you.</remarks>
 public void Dispose()
 {
     if (keyboardControl != null)
     {
         if (restoreUserInput)
         {
             //if this next line returns false, I used to throw an exception...
             Win32.BlockInput(false);
             restoreUserInput = false;
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Initializes the KeyboardController, blocks user input, and sets
        /// the focus on the specified control.
        /// </summary>
        /// <param name="control">The ControlTester to use the keyboard on.</param>
        public void UseOn(ControlTester control)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            keyboardControl = new KeyboardControl(control);

            if (!restoreUserInput)
            {
                //if this next line returns false, I used to throw an exception...
                Win32.BlockInput(true);
                restoreUserInput = true;
            }
        }
예제 #5
0
        /// <summary>
        ///   Releases the resources used by the <see cref="MouseController"/>.
        /// </summary>
        /// <remarks>
        ///   <b>Dispose</b> releases any pressed mouse keys, restores the
        ///   mouse <see cref="Position"/> and enables user input.
        /// </remarks>
        public void Dispose()
        {
            if (mouseControl != null)
            {
                // If we do not have a control, then an exception will be thrown.
                try
                {
                    // Release any pressed mouse buttons.
                    MouseButtons pressedButtons = Control.MouseButtons;
                    if (pressedButtons != MouseButtons.None)
                    {
                        Release(pressedButtons);
                    }

                    // Release any modifier keys.
                    Keys keys = Control.ModifierKeys;
                    if (keys != Keys.None)
                    {
                        Release(keys);
                    }
                }
                catch (AmbiguousNameException)
                {
                }
                catch (NoSuchControlException)
                {
                }
                finally
                {
                    // Restore the mouse position
                    Win32.SetCursorPos(originalPosition.X, originalPosition.Y);

                    // Enable user input.
                    if (restoreUserInput)
                    {
                        if (!Win32.BlockInput(false))
                        {
                            //TODO Bart De Boeck
                            //throw new Win32Exception();
                        }
                        restoreUserInput = false;
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Initializes the KeyboardController, blocks user input, and sets
        /// the focus on the specified control.
        /// </summary>
        /// <param name="control">The ControlTester to use the keyboard on.</param>
        public void UseOn(ReflectionTester control)
        {
            if (control == null)
            {
                throw new ArgumentNullException(nameof(control));
            }

            Control c = control.TheObject as Control;

            FormsAssert.IsTrue(c != null, "Keyboard control requires tester of Control");
            sendKeys = sendKeysFactory.Create(c.Handle);

            keyboardControl = new KeyboardControl(control);

            if (!restoreUserInput)
            {
                //if this next line returns false, I used to throw an exception...
                Win32.BlockInput(true);
                restoreUserInput = true;
            }
        }