Skip to content

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.

getButton(btn): ButtonBinding | undefined

Defined in: packages/threeplay/src/plugins/input/types.ts:105

The physical bindings of a virtual button.

string

ButtonBinding | undefined


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

"left" | "right"

Vector2


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".

string

string

string

string

InputDirOpts

Vector3


isButtonDown(btn): boolean

Defined in: packages/threeplay/src/plugins/input/types.ts:82

true while any of the buttons is held.

string | string[]

boolean


isButtonPressed(btn?): boolean

Defined in: packages/threeplay/src/plugins/input/types.ts:84

true the frame a button went down (any button without arguments).

string | string[]

boolean


isButtonReleased(btn?): boolean

Defined in: packages/threeplay/src/plugins/input/types.ts:86

true the frame a button went up (any button without arguments).

string | string[]

boolean


isGamepadButtonDown(btn): boolean

Defined in: packages/threeplay/src/plugins/input/types.ts:166

true while a gamepad button is held on any pad.

string

boolean


isKeyDown(key): boolean

Defined in: packages/threeplay/src/plugins/input/types.ts:60

true while any of the keys is held.

string | string[]

boolean


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

string | string[]

boolean


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

string | string[]

boolean


isMouseDown(btn?): boolean

Defined in: packages/threeplay/src/plugins/input/types.ts:118

true while a mouse button is held (default "left").

MouseButton

boolean


isMousePressed(btn?): boolean

Defined in: packages/threeplay/src/plugins/input/types.ts:120

true the frame a mouse button went down (default "left").

MouseButton

boolean


isMouseReleased(btn?): boolean

Defined in: packages/threeplay/src/plugins/input/types.ts:122

true the frame a mouse button went up (default "left").

MouseButton

boolean


isPointerLocked(): boolean

Defined in: packages/threeplay/src/plugins/input/types.ts:138

true while the pointer is locked to the canvas.

boolean


isTouchscreen(): boolean

Defined in: packages/threeplay/src/plugins/input/types.ts:160

true on touch devices (or once a touch was seen).

boolean


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.

void


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

Vector2


mousePos(): Vector2

Defined in: packages/threeplay/src/plugins/input/types.ts:111

Mouse position in logical screen coordinates.

Vector2


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.

string | string[]

(btn) => void

EventController

onButtonDown(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:89

(btn) => void

EventController


onButtonPress(btn, fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:91

Runs when a button (or any button) goes down.

string | string[]

(btn) => void

EventController

onButtonPress(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:92

(btn) => void

EventController


onButtonRelease(btn, fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:94

Runs when a button (or any button) goes up.

string | string[]

(btn) => void

EventController

onButtonRelease(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:95

(btn) => void

EventController


onCharInput(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:78

Typed characters (for text entry).

(ch) => void

EventController


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.

string

(obj) => void

EventController

onClick(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:146

Clicks anywhere.

() => void

EventController


onGamepadButtonPress(btn, fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:168

Runs when a gamepad button (or any button) goes down.

string

(btn) => void

EventController

onGamepadButtonPress(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:169

(btn) => void

EventController


onGamepadConnect(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:171

A gamepad was connected.

(pad) => void

EventController


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.

string

(obj) => void

EventController


onHoverEnd(tag, fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:150

When it stops pointing at it.

string

(obj) => void

EventController


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.

string | string[]

(key) => void

EventController

onKeyDown(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:67

(key) => void

EventController


onKeyPress(key, fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:69

Runs when a key (or any key) goes down.

string | string[]

(key) => void

EventController

onKeyPress(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:70

(key) => void

EventController


onKeyPressRepeat(key, fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:72

Like onKeyPress but repeats while held (OS key repeat).

string | string[]

(key) => void

EventController

onKeyPressRepeat(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:73

(key) => void

EventController


onKeyRelease(key, fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:75

Runs when a key (or any key) goes up.

string | string[]

(key) => void

EventController

onKeyRelease(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:76

(key) => void

EventController


onMouseMove(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:130

Runs when the mouse moves.

(pos, delta) => void

EventController


onMousePress(btn, fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:124

Runs when a mouse button (or any button) goes down.

MouseButton

(pos) => void

EventController

onMousePress(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:125

(pos) => void

EventController


onMouseRelease(btn, fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:127

Runs when a mouse button (or any button) goes up.

MouseButton

(pos) => void

EventController

onMouseRelease(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:128

(pos) => void

EventController


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

(delta) => void

EventController


onTouchEnd(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:158

A finger lifted.

(pos, touch) => void

EventController


onTouchMove(fn): EventController

Defined in: packages/threeplay/src/plugins/input/types.ts:156

A finger moved.

(pos, touch) => void

EventController


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.

(pos, touch) => void

EventController


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

string

void


releaseButton(btn): void

Defined in: packages/threeplay/src/plugins/input/types.ts:103

Releases a button pressed with pressButton.

string

void


setButton(btn, binding): void

Defined in: packages/threeplay/src/plugins/input/types.ts:107

Defines or replaces the physical bindings of a virtual button.

string

ButtonBinding

void


unlockPointer(): void

Defined in: packages/threeplay/src/plugins/input/types.ts:136

Releases the pointer lock.

void