Getting key code from keyboard_string?

N

N0ba

Guest
So I've been working on control rebinding. It all works, but obviously when global.up is bound to, for example "W", the game crashes because I'm checking for keyboard_check(global.up), and "W" isn't a number.

Is there any way to convert the input received by keyboard_string into the key code assigned to that character? I apologise if this is a dumb or easily answered question, but I've scoured Google looking for it and have turned up empty handed.
 
N

N0ba

Guest
Check the documentation; from the IDE, press F1 on your keyboard, or press HELP - OPEN MANUAL.
Or on your browser, you can read the documentation from this link : https://docs2.yoyogames.com/index.html?page=source/_build/index.html

Anyway, what you are looking for : https://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/controls/keyboard input/index.html
Yes, I know the manual exists. I use it all the time.

I'm honestly not sure why, but I used ord, and that still caused the game to crash.
 

PlayerOne

Member
So I've been working on control rebinding. It all works, but obviously when global.up is bound to, for example "W", the game crashes because I'm checking for keyboard_check(global.up), and "W" isn't a number.

Is there any way to convert the input received by keyboard_string into the key code assigned to that character? I apologise if this is a dumb or easily answered question, but I've scoured Google looking for it and have turned up empty handed.
You can use this code trick to determine the key id.

Code:
//DRAW GUI
draw_text(50,50,chr(keyboard_key))
 
Yes, I know the manual exists. I use it all the time.

I'm honestly not sure why, but I used ord, and that still caused the game to crash.
I'd suggest for you to post the relevant code (place it inside the insert code like PlayerOne did above) and the error message as well if possible so someone can help you identify the mistake.
 
Top