ludic/docs/language/input/input-key_label.md
Orkuncakilkaya 4979cc0c94 feat: every key on the keyboard is bindable - the F-row, the six-pack, Caps Lock and the numpad
The platform gave these keys no code at all, so a game's rebinding screen could not take
one and nothing said why. Windows asked the active layout what they type and got nothing
(w_vk_char answers 0 for a key with no character); macOS let them fall through to
charactersIgnoringModifiers, which reports NSF1FunctionKey and its neighbours at 0xF704
and up - outside the 256-bit held set either way.

w_keyval and ev_keyval now name them, with the same codes on both: 132-143 F1-F12,
144-149 Home / End / PageUp / PageDown / Insert / Delete, 150 Caps Lock, 152-161 the
numpad digits, 162-166 its * + - . and /. The numpad's Enter is Enter.

Key.F1, Key.Home, Key.Numpad0 and the rest fold at compile time, and Input.key_label
names them without asking the layout - a key that types nothing is called the same thing
on every layout.

examples/library/input_typeless_keys.ludic covers the codes, the names, the held set and
the press edge; 150 passed in ludic-dev test, 33 in selfhost-test.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 00:57:02 +03:00

1.5 KiB

id name category kind tokens sig tip order ns member
input-key_label Input.key_label input namespace-method Input.key_label Input.key_label(key) -> string The name to show a player for a key - in their own keyboard layout. 11 Input key_label

Returns the name to show for key. The letter, digit and punctuation codes that Input.key_down reads are physical keys, named for what they type on a US layout: 'w' is the key above 's' 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 - "W" on QWERTY, "Z" on AZERTY. Space, Enter, Esc, Tab, Backspace, Shift, Ctrl, Alt and the arrows get words, and a code with no name returns "". The keys that type no character - F1-F12, Home, End, PageUp, PageDown, Insert, Delete, Caps Lock and the numpad, codes 132-166 - are named "F1", "Home", "CapsLock", "Num 0", "Num /" and so on, and the layout is not asked: a key that types nothing is called the same thing on every layout.

On Windows the label is read from the active layout. Headless, on macOS and in the browser it is the US character, upper case.

program Demo {
  entry {
    print(Input.key_label('w'))
    print(Input.key_label(32))
    print(Input.key_label(Key.Left))
  }
}