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); }
public void TestFocusSwitchingWithUnfocusableControl() { Screen screen = new Screen(100.0f, 100.0f); Controls.Desktop.ButtonControl one = new Controls.Desktop.ButtonControl(); one.Bounds = new UniRectangle(40, 10, 20, 20); Controls.Control two = new Controls.Control(); two.Bounds = new UniRectangle(40, 40, 20, 20); Controls.Desktop.ButtonControl three = new Controls.Desktop.ButtonControl(); three.Bounds = new UniRectangle(40, 70, 20, 20); screen.Desktop.Children.Add(one); screen.Desktop.Children.Add(two); screen.Desktop.Children.Add(three); screen.FocusedControl = one; screen.InjectKeyPress(Keys.Down); screen.InjectKeyRelease(Keys.Down); Assert.AreSame(three, screen.FocusedControl); }
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); }