Getting Strange Unicode Characters when a physical_keycode corresponds to a number

Godot Version

v4.3.stable.official

Question

I implemented a save/load settings rebind functionality, but I’m having some weirdness when binding keys to numbers.

When it loads the default, or right after binding an InputEventKey to a number key with the event set to physical, it looks fine. But after saving the dictionary to the file, and reloading it, the display no longer shows the number, but instead unicode characters. I’ve attached a screenshot below.

issue

When loading the input event, I use the following code to get the text

var action_bind = OS.get_keycode_string(DisplayServer.keyboard_get_keycode_from_physical(event.physical_keycode))

When saving, i do a JSON.stringify on the payload dictionary, which contains all of the keybinding events, and then a file.store_line() on the resulting json string.

Letters and other keys work fine, its just numbers that make the weird characters.

Perhaps there is an issue with your font.
Change the font.

tried a few different fonts and get the same result.

Finally figured it out. I had followed a tutorial for saving/loading settings and key map data, and while the key map data was being saved properly initially, the loading of the data was incorrect.

the data dictionary would come in as a json string, and the tutorial was doing

int(dictionary.mapping_key), and just parsing the json element as an int. not sure how that worked for the letter mapping, but it seemed to work for letters and other keys, but not the number keys (top row or numpad).

once I replaced that with a custom parser that gets the physical keycode from the json, it works beautifully.

@qmilfox I appreciate the suggestion about the font, that is honestly something that I would never have thought to check in a million years.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.