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, 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) 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

(static) preventDefaultInput :Boolean

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

Type:
  • Boolean

Methods

(static) clearInput()

Clears all input

(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) 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) 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