GML Checking the keyboard

Pep Andorra


I am very confused with the keyboard workflow.

I have two main objects:
- obj_button: simply a button to "close" an obj_window that sends the Escape key

With this code:
show_debug_message ("Press ESC");
keyboard_key_press (vk_escape);
- obj_control (used to control keyboard input)
In the event 'Step' I put this code:
if keyboard_check_pressed (vk_escape) {
show_debug_message ("Key escape processing ...");
Only 80% of tests work well. In the remaining 20%. I see at the exit:
"Press the ESC key", but not "Key Escape Process ..."

I move the code of the event 'Step' code and put in the 'Key Presses -Escape' event without any improvement.
If I press directly the 'Escape' key It continue to work only sometimes!

It seems like sometimes the keyboard input is emptied beetween the key press and the key check.

I hope you can help me to understand whats happen.


Does it work if you put only the following obj_control in the room and run it?

obj_control : Step event
if keyboard_check_pressed (vk_escape) {
    show_debug_message ("Key escape processing ...");


Check your instance ids and event ordering. What is probably happening is the button is running after the control some of the time. Personally I would just use a variable. If escape is actually pressed, set that variable to 1. If you want to simulate escape being pressed, just set the variable directly. Instead of checking if escape is pressed in the control, check if the variable is set.