gamepadConnected(gamepad) → booleanengineInput.js:369Returns true if passed in gamepad is connected
gamepadnumber optional
LittleJS Input System
gamepadConnected(gamepad) → booleanengineInput.js:369Returns true if passed in gamepad is connected
gamepad number optionalgamepadIsDown(button, gamepad) → booleanengineInput.js:312Returns true if gamepad button is down
button numbergamepad number optionalgamepadStick(stick, gamepad) → Vector2engineInput.js:348Returns gamepad stick value
stick numbergamepad number optionalgamepadStickCount(gamepad) → numberengineInput.js:379Returns how many control sticks the passed in gamepad has
gamepad number optionalgamepadVibrate(gamepad, duration, strongMagnitude, weakMagnitude, startDelay)engineInput.js:393Pulse a gamepad's vibration hardware using the dual-rumble effect if it exists Strong magnitude is usually the left side motor, weak magnitude is usually the right side motor
gamepad number optionalgamepad index
duration number optional, default 200effect duration in ms, browsers limit it and the delay to 5 seconds together
strongMagnitude number optional, default 1strong (left) motor intensity, 0 to 1
weakMagnitude number optional, default 1weak (right) motor intensity, 0 to 1
startDelay number optional, default 0delay in ms before the effect starts
gamepadVibrateStop(gamepad)engineInput.js:410Stop vibration on a gamepad
gamepad number optionalgamepad index
gamepadWasPressed(button, gamepad) → booleanengineInput.js:324Returns true if gamepad button was pressed
button numbergamepad number optionalgamepadWasReleased(button, gamepad) → booleanengineInput.js:336Returns true if gamepad button was released
button numbergamepad number optionalinputClear()engineInput.js:189Clears all input
inputClearKey(key, device, clearDown, clearPressed, clearReleased)engineInput.js:133Clear a key's state, so it stops reading as down, pressed or released this frame; a key still held is not pressed again until it is let go
key string|numberA key code like 'Space', or a mouse or gamepad button number
device number optional, default 00 for the keyboard and mouse, gamepad n is device n + 1
clearDown boolean optional, default trueClear the held state
clearPressed boolean optional, default trueClear the pressed this frame state
clearReleased boolean optional, default trueClear the released this frame state
keyDirection(up, down, left, right) → Vector2engineInput.js:267Returns input vector from arrow keys or WASD if enabled
up string optional, default ArrowUpdown string optional, default ArrowDownleft string optional, default ArrowLeftright string optional, default ArrowRightkeyIsDown(key, device) → booleanengineInput.js:220Returns true if device key is down
key string|numberdevice number optional, default 00 for the keyboard and mouse, gamepad n is device n + 1
keyWasPressed(key, device) → booleanengineInput.js:235Returns true if device key was pressed this frame
key string|numberdevice number optional, default 00 for the keyboard and mouse, gamepad n is device n + 1
keyWasReleased(key, device) → booleanengineInput.js:250Returns true if device key was released this frame
key string|numberdevice number optional, default 00 for the keyboard and mouse, gamepad n is device n + 1
mouseWasPressed(button) → booleanengineInput.js:291Returns true if mouse button was pressed
button numbermouseWasReleased(button) → booleanengineInput.js:301Returns true if mouse button was released
button numberpointerLockExit()engineInput.js:461Request to unlock the pointer
pointerLockIsActive() → booleanengineInput.js:470Check if pointer is locked (true if locked)
pointerLockRequest()engineInput.js:447Request to lock the pointer, for a mouse; a device with only touch refuses it, and a press that came from a touch does not ask, since a locked pointer stops the touch gamepad taking its fingers
setInputMouseMoveThreshold(threshold)engineInput.js:110Set the screen-pixel mouse movement per frame that counts as using the mouse
threshold numbersetInputPreventDefault(preventDefault)engineInput.js:105Prevents input continuing to the default browser handling This is useful to disable for html menus so the browser can handle input normally, the right click menu included; over an html text field that menu always shows
preventDefault boolean optional, default truetouchGamepadButtonPos(button) → TouchGamepadButtonPos|undefinedengineInput.js:1586Returns where a button of the touch gamepad is on screen, to draw an icon of the game's own over it
button number// in gameRenderPost, an icon centered in the action button that fades with it
const b = touchGamepadButtonPos(0);
if (b && b.alpha)
{
const color = hsl(0, 0, 1, b.alpha / touchGamepadAlpha); // fades with the buttons
drawTile(b.pos, vec2(b.size * .6), actionIcon, color, 0, false, undefined, glEnable, true);
}usingGamepadInput() → booleanengineInput.js:123Is a gamepad the most recently used input device?
usingKeyboardInput() → booleanengineInput.js:119Is the keyboard the most recently used input device?
usingMouseInput() → booleanengineInput.js:115Is the mouse the most recently used input device?
vibrate(pattern)engineInput.js:431Pulse the vibration hardware if it exists
pattern number|Array<number> optional, default 100single value in ms or vibration interval array
vibrateStop()engineInput.js:439Cancel any ongoing vibration
gamepadPrimary : numberengineInput.js:93Primary gamepad index, automatically set to first gamepad with input
inputMouseMoveThreshold : number default 6engineInput.js:83Screen-pixel mouse movement per frame that counts as "using the mouse" (so sub-pixel hand jitter doesn't steal focus from the keyboard/gamepad).
inputPreventDefault : booleanengineInput.js:88Prevents input continuing to the default browser handling (true by default)
isUsingGamepad : booleanengineInput.js:65True if a gamepad is the most recently used input device. Equivalent to usingGamepadInput(); derived from lastInputDevice each frame.
lastInputDevice : 'mouse'|'keyboard'|'gamepad'engineInput.js:76The most recently used input device: 'mouse' | 'keyboard' | 'gamepad'. Sticky: it holds its value while every device is idle, so a mouse-follow control (e.g. paddle = mousePos) won't snap back the instant the stick/keys are released. With several devices in play at once (e.g. keyboard to move + mouse to aim) it tracks whichever was touched last each frame, so it may alternate — that's intended; use it to pick which control drives a shared action. Updated every frame by inputUpdate().
mouseDelta : Vector2engineInput.js:29Mouse movement delta in world space
mouseDeltaScreen : Vector2engineInput.js:34Mouse movement delta in screen space
mouseInWindow : booleanengineInput.js:59True if mouse was inside the document window, set to false when mouse leaves
mousePos : Vector2engineInput.js:18Mouse pos in world space
mousePosScreen : Vector2engineInput.js:24Mouse pos in screen space, in canvas pixels counted as the draws count them: pixel n is n - .5 to n + .5, so it runs from -.5 to the canvas size less .5, and is a pixel's number when the pointer is over that pixel's middle
mouseWheel : numberengineInput.js:39Mouse wheel delta this frame
touchPinch : numberengineInput.js:46Touch pinch delta this frame, in the mouse wheel's units: two fingers moving apart are negative, as the wheel turned up is, and moving together positive, 1 for every 50 pixels; a trackpad pinch too while touchPinchWheel is on; added to mouseWheel while touchPinchWheel is on, so a game that zooms with the wheel zooms with a pinch
isTouchDeviceengineInput.js:97True if a touch device has been detected
TouchGamepadButtonPos : ObjectengineInput.js:1562Where a touch gamepad button is on screen, its size and how visible it is
pos Vector2Its center in screen space, as mousePosScreen
size numberIts diameter in screen pixels
alpha numberHow visible the gamepad is now, 0 when it has faded out, up to touchGamepadAlpha, 1 in the debug gamepad view