Skip to content

Commit

Permalink
Fix documentation on how to get the keycode string from a `physical_k…
Browse files Browse the repository at this point in the history
…eycode`

Fixes #82091.

Co-authored-by: Yuri Sizov <11782833+YuriSizov@users.noreply.github.com>
Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
  • Loading branch information
3 people committed Nov 9, 2023
1 parent d1381bb commit 1e01fcd
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion doc/classes/InputEventKey.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1e01fcd

Please sign in to comment.