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
- Source
Members
(static) gamepadPrimary :number
Primary gamepad index, automatically set to first gamepad with input
- number
- Source
(static) inputPreventDefault :boolean
Prevents input continuing to the default browser handling (true by default)
- boolean
- Source
(static, constant) isTouchDevice
True if a touch device has been detected
- Source
(static) isUsingGamepad :boolean
Returns true if user is using gamepad (has more recently pressed a gamepad button)
- boolean
- Source
(static) mouseDelta :Vector2
Mouse movement delta in world space
- Vector2
- Source
(static) mouseDeltaScreen :Vector2
Mouse movement delta in screen space
- Vector2
- Source
(static) mouseInWindow :boolean
True if mouse was inside the document window, set to false when mouse leaves
- boolean
- Source
(static) mousePos :Vector2
Mouse pos in world space
- Vector2
- Source
(static) mousePosScreen :Vector2
Mouse pos in screen space
- Vector2
- Source
(static) mouseWheel :number
Mouse wheel delta this frame
- number
- Source
Methods
(static) gamepadConnected(gamepadopt) → {boolean}
Returns true if passed in gamepad is connected
| Name | Type | Attributes | Description |
|---|---|---|---|
gamepad | number | <optional> |
- Source
- Type:
- boolean
(static) gamepadDpad(gamepadopt) → {Vector2}
Returns gamepad dpad value
| Name | Type | Attributes | Description |
|---|---|---|---|
gamepad | number | <optional> |
- Source
- Type:
- Vector2
(static) gamepadIsDown(button, gamepadopt) → {boolean}
Returns true if gamepad button is down
| Name | Type | Attributes | Description |
|---|---|---|---|
button | number | ||
gamepad | number | <optional> |
- Source
- Type:
- boolean
(static) gamepadStick(stick, gamepadopt) → {Vector2}
Returns gamepad stick value
| Name | Type | Attributes | Description |
|---|---|---|---|
stick | number | ||
gamepad | number | <optional> |
- Source
- Type:
- Vector2
(static) gamepadStickCount(gamepadopt) → {number}
Returns how many control sticks the passed in gamepad has
| Name | Type | Attributes | Description |
|---|---|---|---|
gamepad | number | <optional> |
- Source
- Type:
- number
(static) gamepadWasPressed(button, gamepadopt) → {boolean}
Returns true if gamepad button was pressed
| Name | Type | Attributes | Description |
|---|---|---|---|
button | number | ||
gamepad | number | <optional> |
- Source
- Type:
- boolean
(static) gamepadWasReleased(button, gamepadopt) → {boolean}
Returns true if gamepad button was released
| Name | Type | Attributes | Description |
|---|---|---|---|
button | number | ||
gamepad | number | <optional> |
- Source
- Type:
- boolean
(static) inputClear()
Clears all input
- Source
(static) inputClearKey(key, deviceopt, clearDownopt, clearPressedopt, clearReleasedopt)
Clears an input key state
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
key | string | | |||
device | number | <optional> | 0 | |
clearDown | boolean | <optional> | true | |
clearPressed | boolean | <optional> | true | |
clearReleased | boolean | <optional> | true |
- Source
(static) keyDirection(upopt, downopt, leftopt, rightopt) → {Vector2}
Returns input vector from arrow keys or WASD if enabled
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
up | string | <optional> | ArrowUp | |
down | string | <optional> | ArrowDown | |
left | string | <optional> | ArrowLeft | |
right | string | <optional> | ArrowRight |
- Source
- Type:
- Vector2
(static) keyIsDown(key, deviceopt) → {boolean}
Returns true if device key is down
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
key | string | | |||
device | number | <optional> | 0 |
- Source
- Type:
- boolean
(static) keyWasPressed(key, deviceopt) → {boolean}
Returns true if device key was pressed this frame
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
key | string | | |||
device | number | <optional> | 0 |
- Source
- Type:
- boolean
(static) keyWasReleased(key, deviceopt) → {boolean}
Returns true if device key was released this frame
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
key | string | | |||
device | number | <optional> | 0 |
- Source
- Type:
- boolean
(static) mouseIsDown(button) → {boolean}
Returns true if mouse button is down
| Name | Type | Description |
|---|---|---|
button | number |
- Source
- Type:
- boolean
(static) mouseWasPressed(button) → {boolean}
Returns true if mouse button was pressed
| Name | Type | Description |
|---|---|---|
button | number |
- Source
- Type:
- boolean
(static) mouseWasReleased(button) → {boolean}
Returns true if mouse button was released
| Name | Type | Description |
|---|---|---|
button | number |
- Source
- Type:
- boolean
(static) pointerLockExit()
Request to unlock the pointer
- Source
(static) pointerLockIsActive() → {boolean}
Check if pointer is locked (true if locked)
- Source
- Type:
- boolean
(static) pointerLockRequest()
Request to lock the pointer, does not work on touch devices
- Source
(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
| Name | Type | Description |
|---|---|---|
preventDefault | boolean |
- Source
(static) vibrate(patternopt)
Pulse the vibration hardware if it exists
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pattern | number | | <optional> | 100 | single value in ms or vibration interval array |
- Source
(static) vibrateStop()
Cancel any ongoing vibration
- Source