Keys and pointer
A game that already plays with the keyboard or the mouse can be played with the body without changing its code: the SDK turns movements into key presses, or the child’s hand into the mouse.
Keys: data-keys
Section titled “Keys: data-keys”<script src="fabi-play.js" data-keys="jump:Space,left:ArrowLeft,right:ArrowRight,squat:ArrowDown"></script>data-keys maps an action to a key code, action:Code, separated by commas.
| Child’s movement | Action | The key |
|---|---|---|
| Jump | jump |
Pressed while in the air, released on landing (or after 0.8 seconds if no landing is seen) |
| Squat | squat |
Held while the child stays down |
| Step left / right | left / right |
One tap per lane: from the left lane to the right one is two taps |
| Clap | clap |
One tap |
| Arms up | arms-up |
Held while the arms stay up |
With data-keys="default" the most common keys are used: jump Space, squat ArrowDown, left ArrowLeft,
right ArrowRight, clap Enter.
Accepted key codes (as in KeyboardEvent.code): Space, Enter, Escape, ShiftLeft, the arrows (ArrowLeft,
ArrowUp, ArrowRight, ArrowDown), KeyA to KeyZ and Digit0 to Digit9. Any other code throws an error
naming it, when the movement first happens (not when the map is set): try every movement once in the
simulator.
The keys are those of player 1. During an ad no key stays pressed.
From code: FabiPlay.keys() and keyboard()
Section titled “From code: FabiPlay.keys() and keyboard()”The same with code, for example to give a second player other keys:
// script tagFabiPlay.keys({ jump: 'Space', left: 'ArrowLeft', right: 'ArrowRight' })FabiPlay.keys({ jump: 'KeyW', left: 'KeyA', right: 'KeyD' }, { player: 2 })// npmimport { connect, keyboard } from '@fabiplay/sdk'
const play = await connect()const stop = keyboard(play, { jump: 'KeyW' }, { player: 2 }) // returns a function that stops itThe keys go to the page’s active element (or body): where the game’s listeners are, on window, document or a
focused canvas. Each event carries key, code, and the legacy keyCode and which that many games still read.
Pointer: data-pointer
Section titled “Pointer: data-pointer”<script src="fabi-play.js" data-pointer="any"></script>The child’s hand moves the pointer, and holding it still for 0.8 seconds is a click. A round cursor is drawn above
everything, filling up while the hand stays still so the child sees the click coming. data-pointer says which hand
drives it: left, right, or any (the higher one: the hand the child is raising).
The pointer sends mouse and pointer events to whatever is under the hand.
From code: FabiPlay.pointer() and pointer()
Section titled “From code: FabiPlay.pointer() and pointer()”FabiPlay.pointer({ hand: 'right', dwellMs: 1000 })import { connect, pointer } from '@fabiplay/sdk'
const play = await connect()pointer(play, { player: 1, hand: 'any', dwellMs: 800, radius: 0.04 })| Option | Default | Meaning |
|---|---|---|
player |
1 |
Whose hand |
hand |
'any' |
'left', 'right', or 'any' (the higher one) |
dwellMs |
800 |
How long the hand must stay still to click |
radius |
0.04 |
How still: a share of the screen’s diagonal |
The pointer follows the player’s hand pointers (leftHand, rightHand): they are stretched around each child’s
shoulders, so a child reaches every corner of the screen without walking (see
Events and bodies).
Limits
Section titled “Limits”- Simulated keys and clicks have
isTrusted = false. Almost no engine checks this. If yours does, move to level 1. - Unity WebGL reads the keyboard from the canvas: the script sends keys to the active element, so the canvas must have
focus. Alternatively, use level 1 with a small
SendMessagebridge (see Other engines). - There are no fingers: from two or three metres away the camera sees arms and body well, not hands up close.