Keyboard Reference

Xna Input provides a very thin wrapper over the keyboard. Two helper methods are provided:

InputManager.Keyboard.JustPressed(Keys key);
InputManager.Keyboard.JustReleased(Keys key);

To assign a keyboard key to a control, use:

InputManager.AssignControl(PlayerIndex player, string name, Keys key)

This control will return 1.0f when the key is pressed, and 0.0f when it is not.

If you want to use keyboard keys in a situation when an analog range is expected, use:

InputManager.AssignControl(PlayerIndex player, string name, Keys high, Keys low);

This control will return 1.0f while the high key is pressed, -1.0f while the low key is pressed, and 0.0f if both or neither are pressed.

You can also use the equivalent string based methods, if you need to use a user settings file:

InputManager.AssignControl(PlayerIndex player, string name, string source);
InputManager.AssignControl(PlayerIndex player, string name, string high, string low);

The way to form a keyboard key string is "Keyboard" followed by the action you're using (Up, Down, JustPressed, JustReleased) and then the key name, connected by periods.

Last edited Mar 23, 2009 at 4:06 AM by Shader, version 3

Comments

No comments yet.