Skip to content

API Mouse and Keyboard Input

THE_ORONCO edited this page May 19, 2022 · 1 revision

Mouse and Keyboard Input

__EXPERIMENTAL__ -- but mostly working on all platforms

Mouse and keyboard input can be achieved by enabling devkit input mode:

POKE(0x5F2D, flags)  -- where flags are:
flag description
0x1 Enable
0x2 Mouse buttons trigger btn(4)โ€ฆbtn(6)
0x4 Pointer lock (use stat 38โ€ฆ39 to read movements)

Note that not every PICO-8 will have a keyboard or mouse attached to it, so when posting carts to the Lexaloffle BBS, it is encouraged to make keyboard and/or mouse control optional and off by default, if possible. When devkit input mode is enabled, a message is displayed to BBS users warning them that the program may be expecting input beyond the standard 6-button controllers.

The state of the mouse and keyboard can be found in stat(x):

STAT(30) -- (Boolean) True when a keypress is available
STAT(31) -- (String) character returned by keyboard
STAT(32) -- Mouse X
STAT(33) -- Mouse Y
STAT(34) -- Mouse buttons (bitfield)
STAT(36) -- Mouse wheel event
STAT(38) -- Relative x movement (in host desktop pixels) -- requires flag 0x4
STAT(39) -- Relative y movement (in host desktop pixels) -- requires flag 0x4
Clone this wiki locally