diff options
author | jitspoe <jitspoe@yahoo.com> | 2023-09-22 00:58:26 -0400 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-11-09 13:03:29 +0100 |
commit | 1e01fcd0387c0b01768dc2a10de3739e3f21a6e9 (patch) | |
tree | a503ef5c8d56762263a092fce2502cacad7d6462 | |
parent | d1381bbca264794eb3ba470789217ab6f5c91d3f (diff) | |
download | redot-engine-1e01fcd0387c0b01768dc2a10de3739e3f21a6e9.tar.gz |
Fix documentation on how to get the keycode string from a `physical_keycode`
Fixes #82091.
Co-authored-by: Yuri Sizov <11782833+YuriSizov@users.noreply.github.com>
Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
-rw-r--r-- | doc/classes/InputEventKey.xml | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/doc/classes/InputEventKey.xml b/doc/classes/InputEventKey.xml index 5c4dc8e65d..48a6804290 100644 --- a/doc/classes/InputEventKey.xml +++ b/doc/classes/InputEventKey.xml @@ -79,7 +79,25 @@ </member> <member name="physical_keycode" type="int" setter="set_physical_keycode" getter="get_physical_keycode" enum="Key" default="0"> Represents the physical location of a key on the 101/102-key US QWERTY keyboard, which corresponds to one of the [enum Key] constants. - To get a human-readable representation of the [InputEventKey], use [code]OS.get_keycode_string(event.keycode)[/code] where [code]event[/code] is the [InputEventKey]. + To get a human-readable representation of the [InputEventKey], use [method OS.get_keycode_string] in combination with [method DisplayServer.keyboard_get_keycode_from_physical]: + [codeblocks] + [gdscript] + func _input(event): + if event is InputEventKey: + var keycode = DisplayServer.keyboard_get_keycode_from_physical(event.physical_keycode) + print(OS.get_keycode_string(keycode)) + [/gdscript] + [csharp] + public override void _Input(InputEvent @event) + { + if (@event is InputEventKey inputEventKey) + { + var keycode = DisplayServer.KeyboardGetKeycodeFromPhysical(inputEventKey.PhysicalKeycode); + GD.Print(OS.GetKeycodeString(keycode)); + } + } + [/csharp] + [/codeblocks] </member> <member name="pressed" type="bool" setter="set_pressed" getter="is_pressed" default="false"> If [code]true[/code], the key's state is pressed. If [code]false[/code], the key's state is released. |