//check if a key is pressed, and repeat it at the default repeat rate private bool KeyPressWithRepeat(Keys key, double elapsedTime) { if (CurrentKeyState.IsKeyDown(key)) { if (IsKeyPressed(key)) { return(true); //if the key has just been pressed, it automatically counts } keyTimes[key] -= elapsedTime; //count down to next repeat double keyTime = keyTimes[key]; //get the time left if (keyTimes[key] <= 0) //if the time has run out, repeat the letter { keyTimes[key] = repeatInterval; //reset the timer to the repeat interval return(true); } else { return(false); } } //if the key is not pressed, reset it's time to the first interval, which is usually longer else { keyTimes[key] = firstInterval; return(false); } }
public virtual void OnTextInput(TextInputEventArgs e, GameTime gameTime, CurrentKeyState currentKeyState) { for (int i = 0; i < _widgets.Count; i++) { _widgets[i].OnTextInput(e, gameTime, currentKeyState); } }
public void HandleInput() { CurrentKeyState = Keyboard.GetState(); if (!(CurrentKeyState.IsKeyDown(Keys.Right)) && !(CurrentKeyState.IsKeyDown(Keys.Left))) { //dir = 0; IsLeftPressed = false; IsRightPressed = false; if (PlayerState != PLAYER_STATE.IDLE && PlayerState != PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING) { PlayerState = PLAYER_STATE.IDLE; } } if (CurrentKeyState.IsKeyDown(Keys.Right)) { dir = 1; IsLeftPressed = false; IsRightPressed = true; if (Skeleton.FlipX == true) { Skeleton.FlipX = false; } if (PlayerState != PLAYER_STATE.R_RUN && PlayerState != PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING) { PlayerState = PLAYER_STATE.R_RUN; } } else if (CurrentKeyState.IsKeyDown(Keys.Left)) { dir = -1; IsLeftPressed = true; IsRightPressed = false; if (Skeleton.FlipX == false) { Skeleton.FlipX = true; } if (PlayerState != PLAYER_STATE.L_RUN && PlayerState != PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING) { PlayerState = PLAYER_STATE.L_RUN; } } if (PlayerState != PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING && CurrentKeyState.IsKeyDown(Keys.Z) && PrevKeyState.IsKeyUp(Keys.Z)) { IsGrounded = false; PlayerState = PLAYER_STATE.JUMP; IsJumpPressed = true; } if (/*PlayerState == PLAYER_STATE.JUMP && PlayerState != PLAYER_STATE.FALLING * && */CurrentKeyState.IsKeyUp(Keys.Z) && PrevKeyState.IsKeyDown(Keys.Z)) { IsJumpPressed = false; } PrevKeyState = CurrentKeyState; }
/// <summary> /// Takes keyboard input and returns certain characters as a string /// </summary> /// <param name="elapsedTime"></param> /// <returns></returns> private string GetStringFromKeyState(double elapsedTime) { bool shiftPressed = CurrentKeyState.IsKeyDown(Keys.LeftShift) || CurrentKeyState.IsKeyDown(Keys.RightShift); bool altPressed = CurrentKeyState.IsKeyDown(Keys.LeftAlt) || CurrentKeyState.IsKeyDown(Keys.RightAlt); foreach (KeyBinding binding in KeyboardHelper.AmericanBindings) { if (KeyPressWithRepeat(binding.Key, elapsedTime)) { if (!shiftPressed && !altPressed) { return(binding.UnmodifiedString); } else if (shiftPressed && !altPressed) { return(binding.ShiftString); } else if (!shiftPressed && altPressed) { return(binding.AltString); } else if (shiftPressed && altPressed) { return(binding.ShiftAltString); } } } return(""); }
public override void OnKeyDown(Keys key, GameTime gameTime, CurrentKeyState currentKeyState) { if (_menu.Focused) { _menu.OnKeyDown(key, gameTime, currentKeyState); return; } switch (key) { case Keys.W: case Keys.Up: Camera.OffsetPosition(new Vector2(0, -ScrollSpeed / Camera.Zoom) * gameTime.DeltaTime()); break; case Keys.S: case Keys.Down: Camera.OffsetPosition(new Vector2(0, ScrollSpeed / Camera.Zoom) * gameTime.DeltaTime()); break; case Keys.A: case Keys.Left: Camera.OffsetPosition(new Vector2(-ScrollSpeed / Camera.Zoom, 0) * gameTime.DeltaTime()); break; case Keys.D: case Keys.Right: Camera.OffsetPosition(new Vector2(ScrollSpeed / Camera.Zoom, 0) * gameTime.DeltaTime()); break; } }
public override void OnKeyReleased(Keys key, GameTime gameTime, CurrentKeyState currentKeyState) { if (_menu.Focused) { _menu.OnKeyReleased(key, gameTime, currentKeyState); return; } if (key == Keys.OemTilde) { _showDebug = !_showDebug; _menu.GetFrame("debugFrame").Visible = _showDebug; _menu.GetFrame("debugFrame").Active = _showDebug; } else if (key == Keys.Space) { //_lockCamera = !_lockCamera; Camera.CenterPosition(WorldManager.PlayerEntity.Position); } else if (key == Keys.P) { WorldManager.PlayerEntity.Inventory.AddResource(ResourceType.Metal, 100); WorldManager.PlayerEntity.Inventory.AddResource(ResourceType.Gas, 50); } else if (key == Keys.O) { WorldManager.PlayerEntity.BuildShip(ShipType.Miner); } }
public void OnKeyDown(Keys key, GameTime gameTime, CurrentKeyState currentKeyState) { for (int i = 0; i < _widgets.Count; i++) { _widgets[i].OnKeyDown(key, gameTime, currentKeyState); } }
public virtual void OnTextInput(TextInputEventArgs e, GameTime gameTime, CurrentKeyState currentKeyState) { if (!Active) { return; } SceneFrames.OnTextInput(e, gameTime, currentKeyState); }
public virtual void OnKeyDown(Keys key, GameTime gameTime, CurrentKeyState currentKeyState) { if (!Active) { return; } SceneFrames.OnKeyDown(key, gameTime, currentKeyState); }
public static bool IsButtonDown(Keys key) { bool down = false; if (CurrentKeyState.IsKeyDown(key)) { down = true; } return(down); }
public static bool WasButtonPressed(Keys key) { bool pressed = false; if (CurrentKeyState.IsKeyUp(key) && PreviousKeyState.IsKeyDown(key)) { pressed = true; } return(pressed); }
public override void OnKeyReleased(Keys key, GameTime gameTime, CurrentKeyState currentKeyState) { if (Menu.Focused) { Menu.OnKeyReleased(key, gameTime, currentKeyState); return; } if (key == Keys.OemTilde) { #if DEBUG ShowDebug = !ShowDebug; Menu.GetFrame("debugFrame").Visible = ShowDebug; Menu.GetFrame("debugFrame").Active = ShowDebug; #endif } else if (key == Keys.Space) { //_lockCamera = !_lockCamera; Camera.CenterPosition(WorldManager.PlayerEntity.Position); } else if (key == Keys.P) { #if DEBUG WorldManager.PlayerEntity.Inventory.AddAll(1000); #endif } else if (key == Keys.B) { var productionFrame = Menu.GetFrame("frmProduction"); productionFrame.Visible = !productionFrame.Visible; productionFrame.Active = productionFrame.Visible; } else if (key == Keys.Tab) { var helpFrame = Menu.GetFrame("frmHelp"); helpFrame.Visible = !helpFrame.Visible; helpFrame.Active = helpFrame.Visible; } else if (key == Keys.U) { var upgradesFrame = Menu.GetFrame("frmUpgrades"); upgradesFrame.Visible = !upgradesFrame.Visible; upgradesFrame.Active = upgradesFrame.Visible; } } // OnKeyReleased
public override void OnKeyPressed(Keys key, GameTime gameTime, CurrentKeyState currentKeyState) { _menu.OnKeyPressed(key, gameTime, currentKeyState); switch (key) { case Keys.Escape: case Keys.Space: case Keys.Enter: case Keys.Back: { _nextState = GameStateType.Menu; } break; } }
public static bool GetKeyUp(Keys Key, KeyboardFlags keyboardFlags = KeyboardFlags.ANY) { bool BaseCond = CurrentKeyState.IsKeyUp(Key) && LastKeyState.IsKeyDown(Key); switch (keyboardFlags) { case KeyboardFlags.ANY: return(BaseCond); case KeyboardFlags.SOLO: return(BaseCond && Keyboard.GetState().IsKeyUp(Keys.LeftAlt) && Keyboard.GetState().IsKeyUp(Keys.LeftShift) && Keyboard.GetState().IsKeyUp(Keys.LeftControl)); case KeyboardFlags.SHIFT: return(BaseCond && Keyboard.GetState().IsKeyDown(Keys.LeftShift)); case KeyboardFlags.ALT: return(BaseCond && Keyboard.GetState().IsKeyDown(Keys.LeftAlt)); default: return(BaseCond && Keyboard.GetState().IsKeyDown(Keys.LeftControl)); } }
public void OnTextInput(TextInputEventArgs e, GameTime gameTime, CurrentKeyState currentKeyState) { }
public void OnKeyDown(Keys key, GameTime gameTime, CurrentKeyState currentKeyState) { }
public void OnKeyReleased(Keys key, GameTime gameTime, CurrentKeyState currentKeyState) { }
public override void OnKeyPressed(Keys key, GameTime gameTime, CurrentKeyState currentKeyState) { }
public override void OnKeyReleased(Keys key, GameTime gameTime, CurrentKeyState currentKeyState) { _nextGameState = (int)GameStateType.Menu; }
//check if the key has just been pressed private bool IsKeyPressed(Keys key) { return(CurrentKeyState.IsKeyDown(key) && !LastKeyState.IsKeyDown(key)); }
static bool IsKeyReleased(QKeyStates keyState) { return(CurrentKeyState.IsKeyUp((Keys)keyState) && PreviousKeyState.IsKeyDown((Keys)keyState)); }
public override void OnTextInput(TextInputEventArgs e, GameTime gameTime, CurrentKeyState currentKeyState) { _menu.OnTextInput(e, gameTime, currentKeyState); }
public virtual void OnKeyDown(Keys key, GameTime gameTime, CurrentKeyState currentKeyState) { Widgets.OnKeyDown(key, gameTime, currentKeyState); }
public virtual void OnTextInput(TextInputEventArgs e, GameTime gameTime, CurrentKeyState currentKeyState) { Widgets.OnTextInput(e, gameTime, currentKeyState); }
public static bool KeyPressed(Keys key) { return(CurrentKeyState.IsKeyDown(key)); }
public static bool KeyDown(Keys key) { return(LastKeyState.IsKeyUp(key) && CurrentKeyState.IsKeyDown(key)); }
static bool IsAnyKeyHeld() { return(CurrentKeyState.GetPressedKeys().Length > 0 && PreviousKeyState.GetPressedKeys().Length > 0); }
public override void OnKeyDown(Keys key, GameTime gameTime, CurrentKeyState currentKeyState) { _menu.OnKeyDown(key, gameTime, currentKeyState); }
static bool IsNoKey() { return(CurrentKeyState.GetPressedKeys().Length == 0 && PreviousKeyState.GetPressedKeys().Length == 0); }
static bool IsKeyHeld(QKeyStates keyState) { return(CurrentKeyState.IsKeyDown((Keys)keyState)); }