InputAPI
Defined in: packages/threeplay/src/plugins/input/types.ts:57
API of the input plugin. Listeners registered in a scene die with it.
Input is sampled at the start of each frame: isKeyPressed & co. are true
for the whole frame in which the key went down.
Methods
Section titled “Methods”getButton()
Section titled “getButton()”getButton(
btn):ButtonBinding|undefined
Defined in: packages/threeplay/src/plugins/input/types.ts:105
The physical bindings of a virtual button.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”ButtonBinding | undefined
getGamepadStick()
Section titled “getGamepadStick()”getGamepadStick(
stick):Vector2
Defined in: packages/threeplay/src/plugins/input/types.ts:164
Stick position, each axis −1…1, with a dead zone (y grows downwards).
Parameters
Section titled “Parameters”"left" | "right"
Returns
Section titled “Returns”Vector2
inputDir()
Section titled “inputDir()”inputDir(
left?,right?,forward?,back?,opts?):Vector3
Defined in: packages/threeplay/src/plugins/input/types.ts:180
Movement direction from four virtual buttons (and the left stick), as a
unit (or zero) vector on the XZ plane. The default buttons
"left" "right" "up" "down" (arrows + WASD) exist even if you never
defined them. forward is the camera’s heading by default, −Z with
relativeTo: "world".
Parameters
Section titled “Parameters”string
right?
Section titled “right?”string
forward?
Section titled “forward?”string
string
Returns
Section titled “Returns”Vector3
isButtonDown()
Section titled “isButtonDown()”isButtonDown(
btn):boolean
Defined in: packages/threeplay/src/plugins/input/types.ts:82
true while any of the buttons is held.
Parameters
Section titled “Parameters”string | string[]
Returns
Section titled “Returns”boolean
isButtonPressed()
Section titled “isButtonPressed()”isButtonPressed(
btn?):boolean
Defined in: packages/threeplay/src/plugins/input/types.ts:84
true the frame a button went down (any button without arguments).
Parameters
Section titled “Parameters”string | string[]
Returns
Section titled “Returns”boolean
isButtonReleased()
Section titled “isButtonReleased()”isButtonReleased(
btn?):boolean
Defined in: packages/threeplay/src/plugins/input/types.ts:86
true the frame a button went up (any button without arguments).
Parameters
Section titled “Parameters”string | string[]
Returns
Section titled “Returns”boolean
isGamepadButtonDown()
Section titled “isGamepadButtonDown()”isGamepadButtonDown(
btn):boolean
Defined in: packages/threeplay/src/plugins/input/types.ts:166
true while a gamepad button is held on any pad.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”boolean
isKeyDown()
Section titled “isKeyDown()”isKeyDown(
key):boolean
Defined in: packages/threeplay/src/plugins/input/types.ts:60
true while any of the keys is held.
Parameters
Section titled “Parameters”string | string[]
Returns
Section titled “Returns”boolean
isKeyPressed()
Section titled “isKeyPressed()”isKeyPressed(
key?):boolean
Defined in: packages/threeplay/src/plugins/input/types.ts:62
true the frame a key went down (any key when called without arguments).
Parameters
Section titled “Parameters”string | string[]
Returns
Section titled “Returns”boolean
isKeyReleased()
Section titled “isKeyReleased()”isKeyReleased(
key?):boolean
Defined in: packages/threeplay/src/plugins/input/types.ts:64
true the frame a key went up (any key when called without arguments).
Parameters
Section titled “Parameters”string | string[]
Returns
Section titled “Returns”boolean
isMouseDown()
Section titled “isMouseDown()”isMouseDown(
btn?):boolean
Defined in: packages/threeplay/src/plugins/input/types.ts:118
true while a mouse button is held (default "left").
Parameters
Section titled “Parameters”Returns
Section titled “Returns”boolean
isMousePressed()
Section titled “isMousePressed()”isMousePressed(
btn?):boolean
Defined in: packages/threeplay/src/plugins/input/types.ts:120
true the frame a mouse button went down (default "left").
Parameters
Section titled “Parameters”Returns
Section titled “Returns”boolean
isMouseReleased()
Section titled “isMouseReleased()”isMouseReleased(
btn?):boolean
Defined in: packages/threeplay/src/plugins/input/types.ts:122
true the frame a mouse button went up (default "left").
Parameters
Section titled “Parameters”Returns
Section titled “Returns”boolean
isPointerLocked()
Section titled “isPointerLocked()”isPointerLocked():
boolean
Defined in: packages/threeplay/src/plugins/input/types.ts:138
true while the pointer is locked to the canvas.
Returns
Section titled “Returns”boolean
isTouchscreen()
Section titled “isTouchscreen()”isTouchscreen():
boolean
Defined in: packages/threeplay/src/plugins/input/types.ts:160
true on touch devices (or once a touch was seen).
Returns
Section titled “Returns”boolean
lockPointer()
Section titled “lockPointer()”lockPointer():
void
Defined in: packages/threeplay/src/plugins/input/types.ts:134
Locks the pointer to the canvas (first-person controls). Needs a user gesture.
Returns
Section titled “Returns”void
mouseDeltaPos()
Section titled “mouseDeltaPos()”mouseDeltaPos():
Vector2
Defined in: packages/threeplay/src/plugins/input/types.ts:116
Mouse movement accumulated during this frame, in CSS pixels (works while the pointer is locked).
Returns
Section titled “Returns”Vector2
mousePos()
Section titled “mousePos()”mousePos():
Vector2
Defined in: packages/threeplay/src/plugins/input/types.ts:111
Mouse position in logical screen coordinates.
Returns
Section titled “Returns”Vector2
onButtonDown()
Section titled “onButtonDown()”Call Signature
Section titled “Call Signature”onButtonDown(
btn,fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:88
Runs every frame while a button (or any button) is held.
Parameters
Section titled “Parameters”string | string[]
(btn) => void
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”onButtonDown(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:89
Parameters
Section titled “Parameters”(btn) => void
Returns
Section titled “Returns”onButtonPress()
Section titled “onButtonPress()”Call Signature
Section titled “Call Signature”onButtonPress(
btn,fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:91
Runs when a button (or any button) goes down.
Parameters
Section titled “Parameters”string | string[]
(btn) => void
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”onButtonPress(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:92
Parameters
Section titled “Parameters”(btn) => void
Returns
Section titled “Returns”onButtonRelease()
Section titled “onButtonRelease()”Call Signature
Section titled “Call Signature”onButtonRelease(
btn,fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:94
Runs when a button (or any button) goes up.
Parameters
Section titled “Parameters”string | string[]
(btn) => void
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”onButtonRelease(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:95
Parameters
Section titled “Parameters”(btn) => void
Returns
Section titled “Returns”onCharInput()
Section titled “onCharInput()”onCharInput(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:78
Typed characters (for text entry).
Parameters
Section titled “Parameters”(ch) => void
Returns
Section titled “Returns”onClick()
Section titled “onClick()”Call Signature
Section titled “Call Signature”onClick(
tag,fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:144
Clicks (left button) on objects with tag: a raycast against their
meshes, nearest visible hit first, walking up the object tree until an
object with the tag. While the pointer is locked it aims at the screen center.
Parameters
Section titled “Parameters”string
(obj) => void
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”onClick(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:146
Clicks anywhere.
Parameters
Section titled “Parameters”() => void
Returns
Section titled “Returns”onGamepadButtonPress()
Section titled “onGamepadButtonPress()”Call Signature
Section titled “Call Signature”onGamepadButtonPress(
btn,fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:168
Runs when a gamepad button (or any button) goes down.
Parameters
Section titled “Parameters”string
(btn) => void
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”onGamepadButtonPress(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:169
Parameters
Section titled “Parameters”(btn) => void
Returns
Section titled “Returns”onGamepadConnect()
Section titled “onGamepadConnect()”onGamepadConnect(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:171
A gamepad was connected.
Parameters
Section titled “Parameters”(pad) => void
Returns
Section titled “Returns”onHover()
Section titled “onHover()”onHover(
tag,fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:148
When the cursor (or the crosshair while locked) starts pointing at an object with tag.
Parameters
Section titled “Parameters”string
(obj) => void
Returns
Section titled “Returns”onHoverEnd()
Section titled “onHoverEnd()”onHoverEnd(
tag,fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:150
When it stops pointing at it.
Parameters
Section titled “Parameters”string
(obj) => void
Returns
Section titled “Returns”onKeyDown()
Section titled “onKeyDown()”Call Signature
Section titled “Call Signature”onKeyDown(
key,fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:66
Runs every frame while a key (or any key) is held.
Parameters
Section titled “Parameters”string | string[]
(key) => void
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”onKeyDown(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:67
Parameters
Section titled “Parameters”(key) => void
Returns
Section titled “Returns”onKeyPress()
Section titled “onKeyPress()”Call Signature
Section titled “Call Signature”onKeyPress(
key,fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:69
Runs when a key (or any key) goes down.
Parameters
Section titled “Parameters”string | string[]
(key) => void
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”onKeyPress(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:70
Parameters
Section titled “Parameters”(key) => void
Returns
Section titled “Returns”onKeyPressRepeat()
Section titled “onKeyPressRepeat()”Call Signature
Section titled “Call Signature”onKeyPressRepeat(
key,fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:72
Like onKeyPress but repeats while held (OS key repeat).
Parameters
Section titled “Parameters”string | string[]
(key) => void
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”onKeyPressRepeat(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:73
Parameters
Section titled “Parameters”(key) => void
Returns
Section titled “Returns”onKeyRelease()
Section titled “onKeyRelease()”Call Signature
Section titled “Call Signature”onKeyRelease(
key,fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:75
Runs when a key (or any key) goes up.
Parameters
Section titled “Parameters”string | string[]
(key) => void
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”onKeyRelease(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:76
Parameters
Section titled “Parameters”(key) => void
Returns
Section titled “Returns”onMouseMove()
Section titled “onMouseMove()”onMouseMove(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:130
Runs when the mouse moves.
Parameters
Section titled “Parameters”(pos, delta) => void
Returns
Section titled “Returns”onMousePress()
Section titled “onMousePress()”Call Signature
Section titled “Call Signature”onMousePress(
btn,fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:124
Runs when a mouse button (or any button) goes down.
Parameters
Section titled “Parameters”(pos) => void
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”onMousePress(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:125
Parameters
Section titled “Parameters”(pos) => void
Returns
Section titled “Returns”onMouseRelease()
Section titled “onMouseRelease()”Call Signature
Section titled “Call Signature”onMouseRelease(
btn,fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:127
Runs when a mouse button (or any button) goes up.
Parameters
Section titled “Parameters”(pos) => void
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”onMouseRelease(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:128
Parameters
Section titled “Parameters”(pos) => void
Returns
Section titled “Returns”onScroll()
Section titled “onScroll()”onScroll(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:132
Runs on wheel scroll (the page does not scroll while the pointer is over the canvas).
Parameters
Section titled “Parameters”(delta) => void
Returns
Section titled “Returns”onTouchEnd()
Section titled “onTouchEnd()”onTouchEnd(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:158
A finger lifted.
Parameters
Section titled “Parameters”(pos, touch) => void
Returns
Section titled “Returns”onTouchMove()
Section titled “onTouchMove()”onTouchMove(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:156
A finger moved.
Parameters
Section titled “Parameters”(pos, touch) => void
Returns
Section titled “Returns”onTouchStart()
Section titled “onTouchStart()”onTouchStart(
fn):EventController
Defined in: packages/threeplay/src/plugins/input/types.ts:154
A finger touched the canvas. The first finger also acts as the left mouse button.
Parameters
Section titled “Parameters”(pos, touch) => void
Returns
Section titled “Returns”pressButton()
Section titled “pressButton()”pressButton(
btn):void
Defined in: packages/threeplay/src/plugins/input/types.ts:101
Presses a virtual button from code (on-screen controls, bots, tests). Like
every input it takes effect at the start of the next frame and stays down
until releaseButton (it ORs with the button’s physical bindings).
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
releaseButton()
Section titled “releaseButton()”releaseButton(
btn):void
Defined in: packages/threeplay/src/plugins/input/types.ts:103
Releases a button pressed with pressButton.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”void
setButton()
Section titled “setButton()”setButton(
btn,binding):void
Defined in: packages/threeplay/src/plugins/input/types.ts:107
Defines or replaces the physical bindings of a virtual button.
Parameters
Section titled “Parameters”string
binding
Section titled “binding”Returns
Section titled “Returns”void
unlockPointer()
Section titled “unlockPointer()”unlockPointer():
void
Defined in: packages/threeplay/src/plugins/input/types.ts:136
Releases the pointer lock.
Returns
Section titled “Returns”void