Input

LittleJS Input System

  • Tracks keyboard down, pressed, and released
  • Tracks mouse buttons, position, and wheel
  • Tracks multiple analog gamepads
  • Touch input is handled as mouse input
  • Virtual gamepad for touch devices

Members

(static) inputPreventDefault :boolean

Prevents input continuing to the default browser handling (true by default)

Type:
  • boolean

(static, constant) isTouchDevice

True if a touch device has been detected

(static) isUsingGamepad :boolean

Returns true if user is using gamepad (has more recently pressed a gamepad button)

Type:
  • boolean

(static) mouseDelta :Vector2

Mouse movement delta in world space

Type:

(static) mouseDeltaScreen :Vector2

Mouse movement delta in screen space

Type:

(static) mousePos :Vector2

Mouse pos in world space

Type:

(static) mousePosScreen :Vector2

Mouse pos in screen space

Type:

(static) mouseWheel :number

Mouse wheel delta this frame

Type:
  • number

Methods

(static) gamepadIsDown(button, gamepadopt) → {boolean}

Returns true if gamepad button is down

Parameters:
NameTypeAttributesDefaultDescription
buttonnumber
gamepadnumber<optional>
0
Returns:
Type: 
boolean

(static) gamepadStick(stick, gamepadopt) → {Vector2}

Returns gamepad stick value

Parameters:
NameTypeAttributesDefaultDescription
sticknumber
gamepadnumber<optional>
0
Returns:
Type: 
Vector2

(static) gamepadWasPressed(button, gamepadopt) → {boolean}

Returns true if gamepad button was pressed

Parameters:
NameTypeAttributesDefaultDescription
buttonnumber
gamepadnumber<optional>
0
Returns:
Type: 
boolean

(static) gamepadWasReleased(button, gamepadopt) → {boolean}

Returns true if gamepad button was released

Parameters:
NameTypeAttributesDefaultDescription
buttonnumber
gamepadnumber<optional>
0
Returns:
Type: 
boolean

(static) inputClear()

Clears all input

(static) inputClearKey(key, deviceopt, clearDownopt, clearPressedopt, clearReleasedopt)

Clears an input key state

Parameters:
NameTypeAttributesDefaultDescription
keystring | number
devicenumber<optional>
0
clearDownboolean<optional>
true
clearPressedboolean<optional>
true
clearReleasedboolean<optional>
true

(static) keyDirection() → {Vector2}

Returns input vector from arrow keys or WASD if enabled

Returns:
Type: 
Vector2

(static) keyIsDown(key, deviceopt) → {boolean}

Returns true if device key is down

Parameters:
NameTypeAttributesDefaultDescription
keystring | number
devicenumber<optional>
0
Returns:
Type: 
boolean

(static) keyWasPressed(key, deviceopt) → {boolean}

Returns true if device key was pressed this frame

Parameters:
NameTypeAttributesDefaultDescription
keystring | number
devicenumber<optional>
0
Returns:
Type: 
boolean

(static) keyWasReleased(key, deviceopt) → {boolean}

Returns true if device key was released this frame

Parameters:
NameTypeAttributesDefaultDescription
keystring | number
devicenumber<optional>
0
Returns:
Type: 
boolean

(static) mouseIsDown(button) → {boolean}

Returns true if mouse button is down

Parameters:
NameTypeDescription
buttonnumber
Returns:
Type: 
boolean

(static) mouseWasPressed(button) → {boolean}

Returns true if mouse button was pressed

Parameters:
NameTypeDescription
buttonnumber
Returns:
Type: 
boolean

(static) mouseWasReleased(button) → {boolean}

Returns true if mouse button was released

Parameters:
NameTypeDescription
buttonnumber
Returns:
Type: 
boolean

(static) pointerLockExit()

Request to unlock the pointer

(static) pointerLockIsActive() → {boolean}

Check if pointer is locked (true if locked)

Returns:
Type: 
boolean

(static) pointerLockRequest()

Request to lock the pointer, does not work on touch devices

(static) setInputPreventDefault(preventDefault)

Prevents input continuing to the default browser handling This is useful to disable for html menus so the browser can handle input normally

Parameters:
NameTypeDescription
preventDefaultboolean

(static) vibrate(patternopt)

Pulse the vibration hardware if it exists

Parameters:
NameTypeAttributesDefaultDescription
patternnumber | Array<optional>
100

single value in ms or vibration interval array

(static) vibrateStop()

Cancel any ongoing vibration