Keys

Keyboard state and the key constants that name it.

A key is one byte of state in the snapshot App.Input carries. Bit 0 is whether it is currently held, bit 1 whether it was pressed during the input interval, and bit 2 whether it was released during it. Read it through Devices.Snapshot's receivers -- input.devices.key_down(KeyW), key_pressed, key_released -- rather than through the bytes.

The host stores fixed-size state lists with one byte per raylib key code 0 through 348. The named keys cover the whole raylib keyboard enum; Raw(code) through from_code is the backend-specific escape hatch for a key with no name here.

exit_key_code : ExitKey -> I32

Flatten an exit key to the raylib key code the host passes to SetExitKey. 0 is raylib's KEY_NULL, which disables the behaviour. Shared by startup configuration and the runtime SetExitKey command so the two encodings cannot drift.

from_code : U64 -> Try(Key, [InvalidKeyCode, ..])

Validate and wrap a raw raylib key code.

key_code : Key -> U64

raylib key code for a key (index into the snapshot key-state list).

key_down : { ..state, keys : List(U8) }, Key -> Bool

Check if a specific key is currently held down. Pass host directly.

key_up : { ..state, keys : List(U8) }, Key -> Bool

Check if a specific key is currently not pressed (up). Pass host directly.

key_pressed : { ..state, keys : List(U8) }, Key -> Bool

Check if a key was pressed during this input interval. Pass host directly.

key_released : { ..state, keys : List(U8) }, Key -> Bool

Check if a key was released during this input interval. Pass host directly.

Key

:= [
    KeyAndroidBack,
    KeyAndroidMenu,
    KeyVolumeUp,
    KeyVolumeDown,
    KeyApostrophe,
    KeyComma,
    KeyMinus,
    KeyPeriod,
    KeySlash,
    Key0,
    Key1,
    Key2,
    Key3,
    Key4,
    Key5,
    Key6,
    Key7,
    Key8,
    Key9,
    KeySemicolon,
    KeyEqual,
    KeyA,
    KeyB,
    KeyC,
    KeyD,
    KeyE,
    KeyF,
    KeyG,
    KeyH,
    KeyI,
    KeyJ,
    KeyK,
    KeyL,
    KeyM,
    KeyN,
    KeyO,
    KeyP,
    KeyQ,
    KeyR,
    KeyS,
    KeyT,
    KeyU,
    KeyV,
    KeyW,
    KeyX,
    KeyY,
    KeyZ,
    KeyLeftBracket,
    KeyBackslash,
    KeyRightBracket,
    KeyGrave,
    KeySpace,
    KeyEscape,
    KeyEnter,
    KeyTab,
    KeyBackspace,
    KeyInsert,
    KeyDelete,
    KeyRight,
    KeyLeft,
    KeyDown,
    KeyUp,
    KeyPageUp,
    KeyPageDown,
    KeyHome,
    KeyEnd,
    KeyCapsLock,
    KeyScrollLock,
    KeyNumLock,
    KeyPrintScreen,
    KeyPause,
    KeyF1,
    KeyF2,
    KeyF3,
    KeyF4,
    KeyF5,
    KeyF6,
    KeyF7,
    KeyF8,
    KeyF9,
    KeyF10,
    KeyF11,
    KeyF12,
    KeyLeftShift,
    KeyLeftControl,
    KeyLeftAlt,
    KeyLeftSuper,
    KeyRightShift,
    KeyRightControl,
    KeyRightAlt,
    KeyRightSuper,
    KeyKbMenu,
    KeyKp0,
    KeyKp1,
    KeyKp2,
    KeyKp3,
    KeyKp4,
    KeyKp5,
    KeyKp6,
    KeyKp7,
    KeyKp8,
    KeyKp9,
    KeyKpDecimal,
    KeyKpDivide,
    KeyKpMultiply,
    KeyKpSubtract,
    KeyKpAdd,
    KeyKpEnter,
    KeyKpEqual,
    Raw(U64),
]

Named raylib keyboard keys plus a validated backend-specific escape hatch.

is_eq : _

Compare two of these values.

ExitKey

:= [NoExitKey, ExitKey(Key)]

Which key, if any, closes the window. NoExitKey disables the behaviour.

is_eq : _

Compare two of these values.