Keyboard
Currently, there can only be one keyboard present at any time. Users can use the keyboard inputs to control game actions, such as:
- Player Movement
- Menu Selections
- and much more
Mapped Keys:
Here is a list of the mapped keys and their names when using the keyboard:
Registerd Typewriter Keys
KEY_A | KEY_B | KEY_C | KEY_D | KEY_E | KEY_F | KEY_G | KEY_H |
KEY_I | KEY_J | KEY_K | KEY_L | KEY_M | KEY_N | KEY_O | KEY_P |
KEY_Q | KEY_R | KEY_S | KEY_T | KEY_U | KEY_V | KEY_W | KEY_X |
KEY_Y | KEY_Z | KEY_C | KEY_D | KEY_E | KEY_F | KEY_G | KEY_H |
KEY_0 | KEY_1 | KEY_2 | KEY_3 | KEY_4 | KEY_5 | KEY_6 | KEY_7 |
KEY_8 | KEY_9 |
KEY_ENTER | KEY_BACKSPACE | KEY_ESC | KEY_SPACE | KEY_LALT | KEY_LSHIFT |
KEY_LCTRL | KEY_RCTRL | KEY_RALT | KEY_RSHIFT |
Registerd Function Keys
KEY_F1 | KEY_F2 | KEY_F3 | KEY_F4 | KEY_F5 | KEY_F6 | KEY_F7 | KEY_F8 |
KEY_F9 | KEY_F10 | KEY_F11 | KEY_F12 |
Registerd Cursor Control Keys
KEY_UP | KEY_RIGHT | KEY_DOWN | KEY_LEFT |
Keyboard Functions:
Function | Description |
---|---|
just_pressed(key) | The just pressed function is used when the user only wants the key to register once per press, and the reset upon release. |
just_released(key) | This will return true whenever the key argument has been released. |
pressed(key) | Returns true whenever the button is held down. Used when the user needs continuous input from the key. |
Example Usage:
local physics = entity:get_component(Physics)
-- Set the linear velocity of the entity based on the WASD keys
if Keyboard.pressed(KEY_W) then
physics:set_linear_velocity(vec2(0, 50))
elseif Keyboard.pressed(KEY_S) then
physics:set_linear_velocity(vec2(0, -50))
elseif Keyboard.pressed(KEY_A) then
physics:set_linear_velocity(vec2(-50, 0))
elseif Keyboard.pressed(KEY_D) then
physics:set_linear_velocity(vec2(50, 0))
end
-- Have the entity jump if space bar is pressed
if Keyboard.just_pressed(KEY_SPACE) then
physics:linear_impulse(vec2(0, -10000)
end