How do I get a scancode from get_action_list()?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Mr. Gamezz

I’m working on a save and load program and I need keybinds to save as well. When the save button is pressed, It reads the bind from the event list. I tried using the InputMap.get_action_list(“Move_Up”)[0].scancode but it returns an integer instead of a scancode. I need it to return a scancode instead of an interger. The “Move_Up” keybind is currently set to up arrow. When I use the function it just returns “16777232” instead of a keybind. When I try to use that integer as a scancode, The game crashes. How would I get a scancode instead of an integer?

:bust_in_silhouette: Reply From: Inces

Man, scancode is integer, this weird number is exactly the scancode. You are looking for human readable key. You get that by


Also, actions are strings not scancodes. Every action can be assigned more than one event with a scancode. So if you are matchiung scancode, check for event, not action. You can also check for all possible events of each action in actionlist, or check if action has event with certain scancode.

Yes but when I try to use that integer in action_add_event(), It doesn’t work. For example,

var scancode = get_action_list("Move_Up")[0].scancode
action_add_event("Move_Up", scancode)

Trying to run this function crashes the game. Even though the scancode is set to the integer i showed at the initial question.

Mr. Gamezz | 2021-12-16 23:30

But here You are feeding scancode to an action instead of event itself. Scancode is a mere property of event. I am afraid You will have to experiment with if You want to bind it like this.
I was making binds for my game not so long ago and I decided to avoid built-in action map. I have a dictionary of scancodes : custom actions, and I check them in input_ functions. My input also passess through setget function to determine whether action is pressed, held or released. Binding key at runtime is much easier this way - make user choose action and press button, get its scancode, append dictionary with key being scancode, value being action.

Inces | 2021-12-17 07:31