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_AKEY_BKEY_CKEY_DKEY_EKEY_FKEY_GKEY_H
KEY_IKEY_JKEY_KKEY_LKEY_MKEY_NKEY_OKEY_P
KEY_QKEY_RKEY_SKEY_TKEY_UKEY_VKEY_WKEY_X
KEY_YKEY_ZKEY_CKEY_DKEY_EKEY_FKEY_GKEY_H
KEY_0KEY_1KEY_2KEY_3KEY_4KEY_5KEY_6KEY_7
KEY_8KEY_9
KEY_ENTERKEY_BACKSPACEKEY_ESCKEY_SPACEKEY_LALTKEY_LSHIFT
KEY_LCTRLKEY_RCTRLKEY_RALTKEY_RSHIFT

Registerd Function Keys

KEY_F1KEY_F2KEY_F3KEY_F4KEY_F5KEY_F6KEY_F7KEY_F8
KEY_F9KEY_F10KEY_F11KEY_F12

Registerd Cursor Control Keys

KEY_UPKEY_RIGHTKEY_DOWNKEY_LEFT

Keyboard Functions:

FunctionDescription
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