Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

D.7 Keyboard Input Intrinsics

The WASM backend also exposes keyboard state using browser KeyboardEvent.code strings such as ArrowLeft, ArrowRight, KeyW, and Space:

IntrinsicArgsDescription
__key_down__(code_ptr code_len)2Get whether a key is currently held down
__key_pressed__(code_ptr code_len)2Get whether a key transitioned from up to down since the last animation frame
__key_released__(code_ptr code_len)2Get 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.