fix(input): keys are physical positions on every layout; Input.key_label names them
The Windows runtime keyed the held set by the character MapVirtualKeyA gave a virtual key, so a game's WASD belonged to whatever the active layout put there, and with an input method on every letter arrived as VK_PROCESSKEY. The typing block is now read from the scancode (the arrows, numpad and F-keys still by virtual key); macOS reads keyCode the same way. Input.key_label(key) names a key in the player's own layout (Windows) or as its US character elsewhere. Verified on Windows with SendInput into a live window: VK_Z carrying W's scancode holds 'w', VK_PROCESSKEY carrying A's holds 'a', Caps Lock changes nothing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
2a2f463d5b
commit
619476ffed
14 changed files with 60552 additions and 60168 deletions
26
docs/language/input/input-key_label.md
Normal file
26
docs/language/input/input-key_label.md
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
id: input-key_label
|
||||
name: Input.key_label
|
||||
category: input
|
||||
kind: namespace-method
|
||||
tokens: Input.key_label
|
||||
sig: Input.key_label(key) -> string
|
||||
tip: The name to show a player for a key - in their own keyboard layout.
|
||||
order: 11
|
||||
ns: Input
|
||||
member: key_label
|
||||
---
|
||||
|
||||
Returns the name to show for <code>key</code>. The letter, digit and punctuation codes that <a href="input-key_down.html"><code>Input.key_down</code></a> reads are <em>physical</em> keys, named for what they type on a US layout: <code>'w'</code> is the key above <code>'s'</code> on every keyboard, whatever layout, language, input method or Caps Lock state the player has. So WASD is always under the left hand, and the label is what that key types in the player's layout - <code>"W"</code> on QWERTY, <code>"Z"</code> on AZERTY. Space, Enter, Esc, Tab, Backspace, Shift, Ctrl, Alt and the arrows get words, and a code with no name returns <code>""</code>.
|
||||
|
||||
On Windows the label is read from the active layout. Headless, on macOS and in the browser it is the US character, upper case.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
entry {
|
||||
print(Input.key_label('w'))
|
||||
print(Input.key_label(32))
|
||||
print(Input.key_label(Key.Left))
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue