-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OS.get_keycode_string()
returns empty string
#84731
Comments
Try using |
Seems worth clarifying in the docs. |
I also made the same assumption that The solution is not to switch to non-physical keys (in most cases, you want the same physical layout regardless of the configured/printed keyboard layout). The solution was actually written in the docs. To get it from an action name (what most people want I guess), I use the following: func get_key_name(action_name: String, event_index_in_action: int = 0) -> String:
var event: InputEvent = InputMap.action_get_events(action_name)[event_index_in_action]
if not (event is InputEventKey):
return ""
return OS.get_keycode_string(
DisplayServer.keyboard_get_label_from_physical(
event.physical_keycode
)
) |
Thanks, it helped us head toward the right direction. On the issue you see just above, I found limitations when using this for:
Maaack found a solution for this in this PR: The full static func get_text(event : InputEvent) -> String:
# ...
elif event is InputEventKey:
var keycode : Key = event.get_physical_keycode()
if keycode:
keycode = event.get_physical_keycode_with_modifiers()
else:
keycode = event.get_keycode_with_modifiers()
keycode = DisplayServer.keyboard_get_keycode_from_physical(keycode)
return OS.get_keycode_string(keycode) (excerpt should be short enough to be used as a mere code sample, but if you need to copy more and worry about license, know that it's under MIT) EDIT: Label keys are displayed properly, but Unicode keys are still invisible... |
Godot version
v4.1.3.stable.official [f06b6836a]
System information
Godot v4.1.3.stable - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4070 (NVIDIA; 31.0.15.4601) - AMD Ryzen 5 5600X 6-Core Processor (12 Threads)
Issue description
I'm trying to show an interaction hint in UI by getting
InputEventKey
fromInputMap
.Code:
Output:
I expect
OS.get_keycode_string()
returnsE
in this particular example.Steps to reproduce
Download reproduction project, run it, look at the Output.
Minimal reproduction project
os_get_keycode_string_bug.zip
The text was updated successfully, but these errors were encountered: