/// <summary> /// Checks adding/removal of keyboard and mouse /// </summary> void TestConnectedDevices() { Assert.True(Input.HasMouse); Assert.NotNull(Input.Mouse); Assert.True(Input.HasPointer); Assert.NotNull(Input.Pointer); Assert.True(Input.HasKeyboard); Assert.NotNull(Input.Keyboard); Assert.False(Input.HasGamePad); Assert.False(Input.HasGameController); bool keyboardAdded = false; bool keyboardRemoved = false; Input.DeviceRemoved += (sender, args) => { Assert.Equal(DeviceChangedEventType.Removed, args.Type); if (args.Device is KeyboardSimulated) { keyboardRemoved = true; } }; Input.DeviceAdded += (sender, args) => { Assert.Equal(DeviceChangedEventType.Added, args.Type); if (args.Device is KeyboardSimulated) { keyboardAdded = true; } }; // Check keyboard removal InputSourceSimulated.RemoveAllKeyboards(); Assert.True(keyboardRemoved); Assert.False(keyboardAdded); Assert.Null(Input.Keyboard); Assert.False(Input.HasKeyboard); // Check keyboard addition InputSourceSimulated.AddKeyboard(); Assert.True(keyboardAdded); Assert.NotNull(Input.Keyboard); Assert.True(Input.HasKeyboard); // Test not crashing with no keyboard/mouse in a few update loops InputSourceSimulated.RemoveAllKeyboards(); InputSourceSimulated.RemoveAllMice(); for (int i = 0; i < 3; i++) { Input.Update(DrawTime); } // Reset input source state EnableSimulatedInputSource(); }
private void InitializeSimulatedInputSource() { if (InputSourceSimulated != null) { Input.Sources.Clear(); Input.Sources.Add(InputSourceSimulated); MouseSimulated = InputSourceSimulated.AddMouse(); KeyboardSimulated = InputSourceSimulated.AddKeyboard(); } }
public GameTestingSystem(IServiceRegistry registry) : base(registry) { DrawOrder = int.MaxValue; Enabled = true; Visible = true; // Switch to simulated input var input = registry.GetSafeServiceAs <InputManager>(); input.Sources.Clear(); input.Sources.Add(inputSourceSimulated = new InputSourceSimulated()); keyboardSimulated = inputSourceSimulated.AddKeyboard(); mouseSimulated = inputSourceSimulated.AddMouse(); }