Keyboards
BeginnerProgrammer keyboard is the most common input device for desktop games. There are two ways to handle keyboard input in Xenko:
- key states
- KeyEvent listsYou can access both from the input base class. For more information about these options, see the input index
Check keyboard availability
Input.HasKeyboard.Get key states
key states and state changes with the following methods:Note
Xenko doesn’t support retrieving interpreted keys, such as special characters and capital letters.Get key events
Down, or all the keys that have been Pressed since the last update. The key state API isn’t good for this situation, as you have to query each available key separately. key events collections available in the Input base class. KeyEvent has two properties: Key (the affected key) and IsDown (the new state of the key).Example code
public class KeyboardEventsScript : SyncScript{ //Declared public member variables and properties show in Game Studio. public override void Update() { //Perform an action in every update. if (Game.IsRunning) { if (Input.IsKeyDown(Keys.Left)) { this.Entity.Transform.Position.X -= 0.1f; } if (Input.IsKeyDown(Keys.Right)) { this.Entity.Transform.Position.X += 0.1f; } } }}
See also
- Gamepads
- Mouse
- Virtual buttons
- Input overview
