API Mouse and Keyboard Input - THE-ORONCO/pico-8 GitHub Wiki
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