예제 #1
0
        public void TestKeyPressOnFocusAffectingControl()
        {
            Control parent = new Control();

            Controls.Desktop.WindowControl child1 = new Controls.Desktop.WindowControl();
            Controls.Desktop.WindowControl child2 = new Controls.Desktop.WindowControl();
            KeyboardTestControl            child3 = new KeyboardTestControl(true);

            parent.Children.Add(child1);
            parent.Children.Add(child2);
            parent.Children.Add(child3);
            KeyboardTestControl child1child1 = new KeyboardTestControl(false);
            KeyboardTestControl child1child2 = new KeyboardTestControl(false);
            KeyboardTestControl child2child1 = new KeyboardTestControl(false);

            child1.Children.Add(child1child1);
            child1.Children.Add(child1child2);
            child2.Children.Add(child2child1);

            parent.ProcessKeyPress(Keys.A, false);
            Assert.AreEqual(1, child1child1.HeldKeyCount);
            Assert.AreEqual(1, child1child2.HeldKeyCount); // because child 1 returned false
            Assert.AreEqual(0, child2child1.HeldKeyCount); // because its parent affects focus
            Assert.AreEqual(1, child3.HeldKeyCount);       // because it doesn't affect focus
        }
예제 #2
0
        public void TestKeyPressWithActivatedControl()
        {
            Control parent = new Control();

            parent.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
            KeyboardTestControl child1 = new KeyboardTestControl(true);
            KeyboardTestControl child2 = new KeyboardTestControl(true);

            child2.Bounds = new UniRectangle(10.0f, 10.0f, 25.0f, 60.0f);

            parent.Children.Add(child1);
            parent.Children.Add(child2);

            parent.ProcessMouseMove(100.0f, 100.0f, 20.0f, 30.0f);
            parent.ProcessMousePress(MouseButtons.Left);

            Assert.AreEqual(0, child1.HeldKeyCount);
            Assert.AreEqual(0, child2.HeldKeyCount);
            parent.ProcessKeyPress(Keys.A, false);
            Assert.AreEqual(0, child1.HeldKeyCount);
            Assert.AreEqual(1, child2.HeldKeyCount); // Because child 1 was activated
            parent.ProcessKeyRelease(Keys.A);
            Assert.AreEqual(0, child1.HeldKeyCount);
            Assert.AreEqual(0, child2.HeldKeyCount);
        }
예제 #3
0
        public void TestInjectKeyPress()
        {
            Screen screen = new Screen();
            KeyboardTestControl control = new KeyboardTestControl();

            screen.Desktop.Children.Add(control);

            screen.InjectKeyPress(Keys.A);
            Assert.AreEqual(1, control.HeldKeyCount);
        }
예제 #4
0
        public void TestKeyPressWithFocusedControl()
        {
            Screen screen = new Screen(100.0f, 100.0f);
            KeyboardTestControl child1 = new KeyboardTestControl();
            KeyboardTestControl child2 = new KeyboardTestControl();

            screen.Desktop.Children.Add(child1);
            screen.Desktop.Children.Add(child2);

            screen.FocusedControl = child2;

            screen.InjectKeyPress(Keys.A);
            Assert.AreEqual(0, child1.HeldKeyCount);
            Assert.AreEqual(1, child2.HeldKeyCount);
            screen.InjectKeyRelease(Keys.A);
            Assert.AreEqual(0, child1.HeldKeyCount);
            Assert.AreEqual(0, child2.HeldKeyCount);
        }
예제 #5
0
        public void TestKeyPressWithActivatedControl()
        {
            Screen screen = new Screen(100.0f, 100.0f);
            KeyboardTestControl child1 = new KeyboardTestControl();
            KeyboardTestControl child2 = new KeyboardTestControl();

            child2.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
            screen.Desktop.Children.Add(child1);
            screen.Desktop.Children.Add(child2);

            // Click on child 2
            screen.InjectMouseMove(50.0f, 50.0f);
            screen.InjectMousePress(MouseButtons.Left);

            // Now child 2 should be receiving the input instead of child 1
            screen.InjectKeyPress(Keys.A);
            Assert.AreEqual(0, child1.HeldKeyCount);
            Assert.AreEqual(1, child2.HeldKeyCount);
            screen.InjectKeyRelease(Keys.A);
            Assert.AreEqual(0, child1.HeldKeyCount);
            Assert.AreEqual(0, child2.HeldKeyCount);
        }
예제 #6
0
    public void TestKeyPressOnFocusAffectingControl() {
      Control parent = new Control();
      Controls.Desktop.WindowControl child1 = new Controls.Desktop.WindowControl();
      Controls.Desktop.WindowControl child2 = new Controls.Desktop.WindowControl();
      KeyboardTestControl child3 = new KeyboardTestControl(true);
      parent.Children.Add(child1);
      parent.Children.Add(child2);
      parent.Children.Add(child3);
      KeyboardTestControl child1child1 = new KeyboardTestControl(false);
      KeyboardTestControl child1child2 = new KeyboardTestControl(false);
      KeyboardTestControl child2child1 = new KeyboardTestControl(false);
      child1.Children.Add(child1child1);
      child1.Children.Add(child1child2);
      child2.Children.Add(child2child1);

      parent.ProcessKeyPress(Keys.A, false);
      Assert.AreEqual(1, child1child1.HeldKeyCount);
      Assert.AreEqual(1, child1child2.HeldKeyCount); // because child 1 returned false
      Assert.AreEqual(0, child2child1.HeldKeyCount); // because its parent affects focus
      Assert.AreEqual(1, child3.HeldKeyCount); // because it doesn't affect focus
    }
예제 #7
0
    public void TestKeyPressWithActivatedControl() {
      Control parent = new Control();
      parent.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
      KeyboardTestControl child1 = new KeyboardTestControl(true);
      KeyboardTestControl child2 = new KeyboardTestControl(true);
      child2.Bounds = new UniRectangle(10.0f, 10.0f, 25.0f, 60.0f);

      parent.Children.Add(child1);
      parent.Children.Add(child2);

      parent.ProcessMouseMove(100.0f, 100.0f, 20.0f, 30.0f);
      parent.ProcessMousePress(MouseButtons.Left);
      
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(0, child2.HeldKeyCount);
      parent.ProcessKeyPress(Keys.A, false);
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(1, child2.HeldKeyCount); // Because child 1 was activated
      parent.ProcessKeyRelease(Keys.A);
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(0, child2.HeldKeyCount);
    }
예제 #8
0
    public void TestKeyPressWithFocusedControl() {
      Screen screen = new Screen(100.0f, 100.0f);
      KeyboardTestControl child1 = new KeyboardTestControl();
      KeyboardTestControl child2 = new KeyboardTestControl();
      screen.Desktop.Children.Add(child1);
      screen.Desktop.Children.Add(child2);

      screen.FocusedControl = child2;

      screen.InjectKeyPress(Keys.A);
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(1, child2.HeldKeyCount);
      screen.InjectKeyRelease(Keys.A);
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(0, child2.HeldKeyCount);
    }
예제 #9
0
    public void TestKeyPressWithActivatedControl() {
      Screen screen = new Screen(100.0f, 100.0f);
      KeyboardTestControl child1 = new KeyboardTestControl();
      KeyboardTestControl child2 = new KeyboardTestControl();
      child2.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
      screen.Desktop.Children.Add(child1);
      screen.Desktop.Children.Add(child2);

      // Click on child 2
      screen.InjectMouseMove(50.0f, 50.0f);
      screen.InjectMousePress(MouseButtons.Left);

      // Now child 2 should be receiving the input instead of child 1
      screen.InjectKeyPress(Keys.A);
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(1, child2.HeldKeyCount);
      screen.InjectKeyRelease(Keys.A);
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(0, child2.HeldKeyCount);
    }
예제 #10
0
    public void TestInjectKeyPress() {
      Screen screen = new Screen();
      KeyboardTestControl control = new KeyboardTestControl();
      screen.Desktop.Children.Add(control);

      screen.InjectKeyPress(Keys.A);
      Assert.AreEqual(1, control.HeldKeyCount);
    }