protected Game2D(int defaultScreenWidth = 800, int defaultScreenHeight = 600, bool fullscreen = false, bool useGamePad = false, DepthFormat depthFormat = DepthFormat.None, string configFileName = null) { _configFileName = string.IsNullOrEmpty(configFileName) ? DefaultConfigFileName : configFileName; LoadGameProperties(); var width = GetScreenSizeComponent(defaultScreenWidth, GameProperty.GameResolutionXProperty, 800); var height = GetScreenSizeComponent(defaultScreenHeight, GameProperty.GameResolutionYProperty, 600); GraphicsDeviceManager = new GraphicsDeviceManager(this) { PreferredBackBufferWidth = width, PreferredBackBufferHeight = height, PreferredDepthStencilFormat = depthFormat, IsFullScreen = fullscreen }; Content.RootDirectory = "Content"; Keyboard = new KeyboardEx(); Mouse = new MouseEx(); GuiSystem = new GuiSystem(this); DepthRenderer = new DepthRenderer(); Cursor = new Cursor(this); if (useGamePad) { GamePad = new GamePadEx(); } _clearOptions = ClearOptions.Target; if (depthFormat != DepthFormat.None) { _clearOptions |= ClearOptions.DepthBuffer; } _registeredGlobals = new Dictionary <string, GameObject>(); }
protected Game2D(int screenWidth, int screenHeight, bool fullscreen, bool useGamePad = false, DepthFormat depthFormat = DepthFormat.None) { GraphicsDeviceManager = new GraphicsDeviceManager(this) { PreferredBackBufferWidth = screenWidth, PreferredBackBufferHeight = screenHeight, PreferredDepthStencilFormat = depthFormat, IsFullScreen = fullscreen }; Content.RootDirectory = "Content"; Keyboard = new KeyboardEx(); Mouse = new MouseEx(); DepthRenderer = new DepthRenderer(); ScriptRunner = new ScriptRunner(this); if (useGamePad) { GamePad = new GamePadEx(); } _clearOptions = ClearOptions.Target; if (depthFormat != DepthFormat.None) { _clearOptions |= ClearOptions.DepthBuffer; } _registeredGlobals = new Dictionary <string, GameObject>(); }
public void TypeText_TypeLowerTextWithShiftHoldDown_TheTextAppearsInupperCase() { KeyboardEx.TypeText(_textBox, "demo", ModifierKeys.Shift, 50).And.Wait(2000); Assert.AreEqual("DEMO", _textBox.Text); _textBox.Unsafe.SetValue(""); }
public void TypeText_TypeLowerTextWithShiftHoldDownSeparatelly_TheTextAppearsInupperCase() { KeyboardEx.PressKey(_textBox, ModifierKeys.Shift); KeyboardEx.TypeText("demo", 50); KeyboardEx.ReleaseKey(ModifierKeys.Shift).And.Wait(2000); Assert.AreEqual("DEMO", _textBox.Text); _textBox.Unsafe.SetValue(""); }
public void TypeText_SomeText_TextIsWritten() { Assert.AreEqual("", _textBox.Text); KeyboardEx.TypeText(_textBox, "Anything Nice", 50).And.Wait(2000); Assert.AreEqual("Anything Nice", _textBox.Text); _textBox.Unsafe.SetValue(""); }
public void TypeKey_ControlAAfterTypingText_AllGetsSelected() { KeyboardEx.TypeText(_textBox, "Peter Sausage"); DynamicSleep.Wait(1000); KeyboardEx.TypeKey(_textBox, Key.A, ModifierKeys.Control).And.Wait(2000); Assert.AreEqual("Peter Sausage", _textBox.SelectedText); _textBox.Unsafe.SetValue(""); }
public void TypeText_PressShiftAndArrowLeftSevenTimes_SelectsPartOfTheText() { KeyboardEx.TypeText(_textBox, "Peter Sausage"); DynamicSleep.Wait(1000); Do.Action(() => KeyboardEx.TypeKey(Key.Left, ModifierKeys.Shift)).Repeat(6).And.Wait(500); Assert.AreEqual("Sausage", _textBox.SelectedText); _textBox.Unsafe.SetValue(""); }
public void Update(KeyboardEx keyboard, float elapsedTime) { if (keyboard.IsKeyDownOnce(Keys.Back) && CurrentText.Length > 0) { CurrentText = CurrentText.Substring(0, CurrentText.Length - 1); } else if (CurrentText.Length < MaxInputCharacters) { var allPressedKeys = keyboard.GetPressedKeys(); var allValidPressedKeys = allPressedKeys.Where(k => _validCharacterCodes.Contains(k.ToString())).ToArray(); foreach (var pressedKey in allValidPressedKeys) { if (_lastPressedKeys.Contains(pressedKey)) { continue; } _lastPressedKeys.Add(pressedKey); var pressed = pressedKey.ToString(); if (!IsAnyShiftKeyDown(keyboard)) { pressed = pressed.ToLower(); } if (pressed.Equals("space")) { pressed = " "; } else if (pressed.Length == 2 && pressed[0] == 'd') { pressed = pressed.Substring(1); } if (InputType == InputType.Numeric && pressed == "d") { break; } if (pressedKey == Keys.OemPeriod) { CurrentText += "."; } else { CurrentText += pressed; } } _lastPressedKeys.Clear(); _lastPressedKeys.AddRange(allValidPressedKeys); } }
public static void Update(GameTime gameTime) { GamePadEx.Update(gameTime); KeyboardEx.Update(gameTime); TouchPanelEx.Update(gameTime); if (CurrentScreen != null) { CurrentScreen.Update(gameTime); } }
public void TypeKey_AltF4OnTheWindow_ClosesTheWindow() { KeyboardEx.TypeKey(_testWindow, Key.F4, ModifierKeys.Alt).And.Wait(2000); var testWindow = WindowFinder.Search(Use.AutomationId("CUI_KeyboardExTestsWindow"), And.NoAssert().And.Timeout(2000)); Assert.IsNull(testWindow); var currentButton = UI.GetChild <BasicButton>(By.AutomationId("CUI_KeyboardExTests_Button"), From.Element(_mainWindow)); currentButton.Unsafe.Click(); DynamicSleep.Wait(1000); _testWindow = WindowFinder.Search(Use.AutomationId("CUI_KeyboardExTestsWindow"), And.NoAssert()); _textBox = UI.GetChild <BasicEdit>(By.AutomationId("CUI_InputTextBox"), From.Element(_testWindow)); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } MouseEx.Update(); KeyboardEx.Update(); // TODO: Add your update logic here _gameStateManager.Update(gameTime); base.Update(gameTime); }
public void TypeText_MoreDifferentShiftSelections_SelectsTheTextAccordingly() { KeyboardEx.TypeText(_textBox, "Peter Sausage"); KeyboardEx.PressKey(Key.Enter); KeyboardEx.TypeText("Was Here"); DynamicSleep.Wait(1000); KeyboardEx.TypeKey(Key.Left, ModifierKeys.Shift); KeyboardEx.TypeKey(Key.Left, ModifierKeys.Shift); KeyboardEx.TypeKey(Key.Left, ModifierKeys.Shift); KeyboardEx.TypeKey(Key.Up, ModifierKeys.Shift); KeyboardEx.TypeKey(Key.Left, ModifierKeys.Shift).And.Wait(2000); Assert.AreEqual("Sausage\r\nWas Here", _textBox.SelectedText); _textBox.Unsafe.SetValue(""); }
public void BringOnTop_TypesTextToDifferentWindows_TheWindowsGetsTheTextAccordingly() { var window1 = WindowFinder.Search(Use.AutomationId("CUI_WindowFocusTestsWindow_1")); var window2 = WindowFinder.Search(Use.AutomationId("CUI_WindowFocusTestsWindow_2")); var textBox1 = UI.GetChild <BasicEdit>(By.AutomationId("CUI_InputTextBox"), From.Element(window1)); var textBox2 = UI.GetChild <BasicEdit>(By.AutomationId("CUI_InputTextBox"), From.Element(window2)); WindowFocus.BringOnTop(window1); MouseEx.Click(window1); KeyboardEx.TypeText("First Window Text").And.Wait(1000); WindowFocus.BringOnTop(window2); MouseEx.Click(window2); KeyboardEx.TypeText("Second Window Text").And.Wait(1000); Assert.AreEqual("First Window Text", textBox1.Text); Assert.AreEqual("Second Window Text", textBox2.Text); }
private void Window_KeyDown(object sender, KeyEventArgs e) { var kbMod = KeyboardEx.GetKeyboardModifiers(); switch (e.Key) { case Key.X: if (kbMod.Alt) { DictionaryCtrl.Extract(); } break; case Key.Enter: case Key.Escape: Close(); break; } }
private static bool IsAnyShiftKeyDown(KeyboardEx keyboard) { return(keyboard.IsKeyDownOnce(Keys.RightShift) || keyboard.IsKeyDown(Keys.LeftShift)); }