/// <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;
            }
        }
Exemple #2
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("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...
                User32.BlockInput(true);
                restoreUserInput = true;
            }
        }
 /// <summary>
 ///   Creates and initialises a new instance of the class for the specified tester.
 /// </summary>
 /// <remarks>
 ///   The <see cref="Position">mouse position</see> is relative to the <see cref="Control"/> managed by
 ///   the <paramref name="controlTester"/>.
 ///   <para>
 ///   While the <b>MouseController</b> is active, user keyboard and mouse input is disabled.  For this
 ///   reason the <b>MouseController</b> should be disposed of when the testing is concluded.
 ///   </para>
 /// </remarks>
 /// <example>
 /// <code>
 /// using (MouseController mouse = new MouseControler(myTestControl))
 /// {
 ///   mouse.Position = new PointF(1,1);
 ///   mouse.PressAndRelease(MouseButtons.Middle);
 /// }
 /// </code>
 /// </example>
 public MouseController(ReflectionTester controlTester)
 {
     UseOn(controlTester);
 }
Exemple #4
0
 internal MouseControl(ReflectionTester tester)
 {
     this.tester = tester;
 }
Exemple #5
0
 internal KeyboardControl(ReflectionTester tester)
 {
     this.tester = tester;
 }