Class KeyboardManager
The default keyboard manager. It tracks which keys went down or up between frames.
public class KeyboardManager : IKeyboardManager
- Inheritance
-
KeyboardManager
- Implements
- Inherited Members
Constructors
KeyboardManager(ILogger<KeyboardManager>)
Created by dependency injection. Reads the keyboard once, so that the first frame has a previous state.
public KeyboardManager(ILogger<KeyboardManager> logger)
Parameters
loggerILogger<KeyboardManager>
Properties
CurrentState
The keyboard state this frame.
public Keyboard.Snapshot CurrentState { get; }
Property Value
KeysDown
The keys that went down since the last frame.
public IEnumerable<Key> KeysDown { get; }
Property Value
KeysPressed
The keys held down this frame.
public IEnumerable<Key> KeysPressed { get; }
Property Value
KeysRepeated
Keys the OS repeated this frame because they are being held. Empty on the frame a key is first pressed - that one is in KeysDown - and a key held long enough appears here once per repeat, so it can appear more than once in a slow frame.
public IEnumerable<Key> KeysRepeated { get; }
Property Value
Remarks
Separate from KeysDown rather than folded into it, because most actions must NOT repeat: held movement is read as a level and paced by the game, and a held Enter must not submit a form thirty times a second. Repeating is opt-in, and the handlers that want it are the text-editing ones.
KeysUp
The keys that went up since the last frame.
public IEnumerable<Key> KeysUp { get; }
Property Value
PreviousState
The keyboard state the frame before.
public Keyboard.Snapshot PreviousState { get; }
Property Value
Methods
IsKeyPressed(Key)
Whether the key went down this frame.
public bool IsKeyPressed(Key key)
Parameters
keyKey
Returns
IsKeyReleased(Key)
Whether the key went up this frame.
public bool IsKeyReleased(Key key)
Parameters
keyKey
Returns
Update(IGameTime)
Reads the keyboard for this frame.
public void Update(IGameTime gameTime)
Parameters
gameTimeIGameTime