keyboard¶
Key presses can be detected using two methods:
key_pressed¶
-
int
key_pressed
(int key)¶ Checks if a specific key has been pressed. This will return 0 after the first positive test, so you will get 1 only once.
- Parameters
key
-Key to test
void update_super_cool_level(void* data, float elapsed_ms) { if (key_pressed(KB_SPACE)) { // do something once per key click } }
- Return
- 1 if the key was pressed or 0 otherwise
key_down¶
-
int
key_down
(int key)¶ Check if a specific key is being held down. This will return 1 as long as the key is being held down.
- Parameters
key
-Key to test
void update_super_cool_level(void* data, float elapsed_ms) { if (key_down(KB_RIGHT)) { // do something } }
- Return
- 1 if the key is being held down or 0 otherwise
key symbols¶
These symbols can be used for key_pressed() or key_down():
KB_SPACE | KB_W |
KB_RIGHT | KB_S |
KB_LEFT | KB_A |
KB_UP | KB_D |
KB_DOWN | |
KB_ESC |