To check for keyboard input in GameMaker, you typically use the function
keyboard_check(key) for continuous checks, or
keyboard_check_released(key) for single events.
Here is how you might use these functions:
In these examples,
vk_right are virtual key codes representing the left arrow key, spacebar, and right arrow key, respectively. GameMaker provides a wide range of constants for various keys on the keyboard such as
For custom key mappings or checking alphanumeric keys, you need to provide the appropriate ASCII value or use GameMaker's built-in constants like
ord("A") for the 'A' key:
Make sure to place your keyboard check code within an appropriate event such as the Step event of an object, so that it gets executed continuously or whenever you need it to check for key presses.
Additionally, you can also check if any key is pressed using
keyboard_check_any(), which returns true if any key is currently being pressed.
GameMaker also provides
keyboard_lastkey which holds the key code of the last key that was pressed, which can be handy in certain scenarios.
Remember that keyboard input can vary depending on the system the game is running on, so ensure to test your game across different systems if possible.