GML How to detect any press on Keyboard / GPad?


Hey guys,

is there a smart way for detecting any keypress on keyboard or GPad?

The reason for this: If an icon of the button you have to press for an action is shown up (Like press A-Button on GPad to continue), it should show the icon of which control the player is using at the moment.
I have a global.active_control variable, which keeps track of the active control, and an object which should do something like this:

if( gamepad_button_check_pressed( device, ANY_BUTTON ) ){
    global.active_control = "Gamepad";
}else if( keyboard_check_pressed( ANY_BUTTON ) ){
    global.active_control = "Keyboard";
For sure, I could hardcode any possibility of what you can press. But is there something smarter than this?


Well for the keyboard, you have the variable keyboard_lastkey, what you can clear when you need to start waiting for a key press and then every step check if it has a value. For gamepads, unless I'm mistaken, you would need 2 run a for loop every step and poll the state of each button on the GamePad. And if you're going to use analog sticks, then you would need to poll the values of the analog sticks. Someone might have a better idea, but that's how I handled it the last time I set up a gamepad.


Hey, the keyboard_lastkey sounds great, I will use that. For the Gamepad thing - this is definetly a smarter solution, but still huge. I rather want to use a very long if-statement then.

Thanks for reply!