D.7 Keyboard Input Intrinsics
The WASM backend also exposes keyboard state using browser KeyboardEvent.code strings such as ArrowLeft, ArrowRight, KeyW, and Space:
| Intrinsic | Args | Description |
|---|---|---|
__key_down__(code_ptr code_len) | 2 | Get whether a key is currently held down |
__key_pressed__(code_ptr code_len) | 2 | Get whether a key transitioned from up to down since the last animation frame |
__key_released__(code_ptr code_len) | 2 | Get whether a key transitioned from down to up since the last animation frame |
These intrinsics are intended for animated WASM programs running under canvas or WebGL, where main() is called once per frame.
While a canvas, WebGL or GPU surface has the page, keys that would scroll it or move focus (arrows, Space, Tab, Backspace, PageUp/PageDown, Home/End, /, ') act only as program input; other keys, and any key held with Ctrl, Alt or Meta, keep their browser behavior. A key press or a click also unlocks audio (D.10).