InputsManager
Table of contents
- accelKey
- altKey
- buttons
- ctrlKey
- currentPagePoint
- currentScreenPoint
- disposables
- editor
- isDragging
- isEditing
- isPanning
- isPen
- isPinching
- isPointing
- isSpacebarPanning
- keys
- metaKey
- originPagePoint
- originScreenPoint
- pointerVelocity
- previousPagePoint
- previousScreenPoint
- shiftKey
- Properties
- Methods
- addEditorEvent
- getAccelKey
- getAltKey
- getCtrlKey
- getCurrentPagePoint
- getCurrentScreenPoint
- getIsDragging
- getIsEditing
- getIsPanning
- getIsPen
- getIsPinching
- getIsPointing
- getIsRightPointing
- getIsSpacebarPanning
- getMetaKey
- getOriginPagePoint
- getOriginScreenPoint
- getPointerVelocity
- getPreviousPagePoint
- getPreviousScreenPoint
- getShiftKey
- markActivity
- register
- setIsDragging
- setIsEditing
- setIsPen
- toJson
Extends EditorManager.
class InputsManager extends EditorManager {}Constructor
Constructs a new instance of the InputsManager class
Parameters
| Name | Description |
|---|---|
|
Properties
accelKey
Deprecated:
Use getAccelKey() instead.
get accelKey(): boolean;altKey
Deprecated:
Use getAltKey() instead.
get altKey(): boolean;
set altKey(altKey: boolean);buttons
A set containing the currently pressed buttons.
readonly buttons: AtomSet<number>;ctrlKey
Deprecated:
Use getCtrlKey() instead.
get ctrlKey(): boolean;
set ctrlKey(ctrlKey: boolean);currentPagePoint
Deprecated:
Use getCurrentPagePoint() instead.
get currentPagePoint(): Vec;currentScreenPoint
Deprecated:
Use getCurrentScreenPoint() instead.
get currentScreenPoint(): Vec;disposables
protected readonly disposables: Set<() => void>;editor
protected readonly editor: Editor;isDragging
Soon to be deprecated, use getIsDragging() instead.
get isDragging(): boolean;
set isDragging(isDragging: boolean);isEditing
Deprecated:
Use getIsEditing() instead.
get isEditing(): boolean;
set isEditing(isEditing: boolean);isPanning
Deprecated:
Use getIsPanning() instead.
get isPanning(): boolean;
set isPanning(isPanning: boolean);isPen
Deprecated:
Use getIsPen() instead.
get isPen(): boolean;
set isPen(isPen: boolean);isPinching
Deprecated:
Use getIsPinching() instead.
get isPinching(): boolean;
set isPinching(isPinching: boolean);isPointing
Deprecated:
Use getIsPointing() instead.
get isPointing(): boolean;
set isPointing(isPointing: boolean);isSpacebarPanning
Deprecated:
Use getIsSpacebarPanning() instead.
get isSpacebarPanning(): boolean;
set isSpacebarPanning(isSpacebarPanning: boolean);keys
A set containing the currently pressed keys.
readonly keys: AtomSet<string>;metaKey
Deprecated:
Use getMetaKey() instead.
get metaKey(): boolean;
set metaKey(metaKey: boolean);originPagePoint
Deprecated:
Use getOriginPagePoint() instead.
get originPagePoint(): Vec;originScreenPoint
Deprecated:
Use getOriginScreenPoint() instead.
get originScreenPoint(): Vec;pointerVelocity
Deprecated:
Use getPointerVelocity() instead.
get pointerVelocity(): Vec;previousPagePoint
Deprecated:
Use getPreviousPagePoint() instead.
get previousPagePoint(): Vec;previousScreenPoint
Deprecated:
Use getPreviousScreenPoint() instead.
get previousScreenPoint(): Vec;shiftKey
Deprecated:
Use getShiftKey() instead.
get shiftKey(): boolean;
set shiftKey(shiftKey: boolean);Methods
addEditorEvent( )
Subscribe to an editor bus event and register the matching unsubscribe, so the listener is removed automatically on dispose().
protected addEditorEvent<E extends keyof TLEventMap>(
event: E,
fn: (...args: TLEventMap[E]) => void,
): void;Parameters
| Name | Description |
|---|---|
| |
| |
Returns
void;getAccelKey( )
Is the accelerator key (cmd on mac, ctrl elsewhere) currently pressed.
getAccelKey(): boolean;getAltKey( )
Whether the alt or option key is currently pressed.
getAltKey(): boolean;getCtrlKey( )
Whether the ctrl or command key is currently pressed.
getCtrlKey(): boolean;getCurrentPagePoint( )
The most recent pointer position in the current page space.
getCurrentPagePoint(): Vec;getCurrentScreenPoint( )
The most recent pointer position in screen space.
getCurrentScreenPoint(): Vec;getIsDragging( )
Whether the user is dragging.
getIsDragging(): boolean;getIsEditing( )
Whether the user is editing.
getIsEditing(): boolean;getIsPanning( )
Whether the user is panning.
getIsPanning(): boolean;getIsPen( )
Whether the input is from a pen.
getIsPen(): boolean;getIsPinching( )
Whether the user is pinching.
getIsPinching(): boolean;getIsPointing( )
Whether the user is pointing.
getIsPointing(): boolean;getIsRightPointing( )
Whether the user is right-click pointing (before drag threshold).
getIsRightPointing(): boolean;getIsSpacebarPanning( )
Whether the user is spacebar panning.
getIsSpacebarPanning(): boolean;getMetaKey( )
Whether the meta key is currently pressed.
getMetaKey(): boolean;getOriginPagePoint( )
The most recent pointer down's position in the current page space.
getOriginPagePoint(): Vec;getOriginScreenPoint( )
The most recent pointer down's position in screen space.
getOriginScreenPoint(): Vec;getPointerVelocity( )
Velocity of mouse pointer, in pixels per millisecond.
getPointerVelocity(): Vec;getPreviousPagePoint( )
The previous pointer position in the current page space.
getPreviousPagePoint(): Vec;getPreviousScreenPoint( )
The previous pointer position in screen space.
getPreviousScreenPoint(): Vec;getShiftKey( )
Whether the shift key is currently pressed.
getShiftKey(): boolean;markActivity( )
Mark the current user as active for collaborator presence. User input anywhere in the editor's tab counts as activity automatically; call this to make input that doesn't produce DOM events count too, so peers don't classify this user as idle or inactive while they're still interacting. Calls are throttled on the leading edge, so it's safe to call from high-frequency input events.
markActivity(): void;Example
// Gamepads are polled rather than event-driven, so stamp activity from the poll
editor.timers.setInterval(() => {
const isPressed = navigator
.getGamepads()
.some((pad) => pad?.buttons.some((button) => button.pressed));
if (isPressed) editor.inputs.markActivity();
}, 50);register( )
Register a teardown function to run on dispose(). The universal way for a manager to make a resource "see itself out". Returns the same function for convenience.
protected register(dispose: () => void): () => void;Parameters
| Name | Description |
|---|---|
| |
Returns
() => void;setIsDragging( )
setIsDragging(isDragging: boolean): void;Parameters
| Name | Description |
|---|---|
| Whether the user is dragging. |
Returns
void;setIsEditing( )
setIsEditing(isEditing: boolean): void;Parameters
| Name | Description |
|---|---|
| Whether the user is editing. |
Returns
void;setIsPen( )
setIsPen(isPen: boolean): void;Parameters
| Name | Description |
|---|---|
| Whether the input is from a pen. |
Returns
void;toJson( )
toJson(): {
altKey: boolean;
buttons: number[];
ctrlKey: boolean;
currentPagePoint: import("@tldraw/tlschema").VecModel;
currentScreenPoint: import("@tldraw/tlschema").VecModel;
isDragging: boolean;
isEditing: boolean;
isPanning: boolean;
isPen: boolean;
isPinching: boolean;
isPointing: boolean;
isSpacebarPanning: boolean;
keys: string[];
metaKey: boolean;
originPagePoint: import("@tldraw/tlschema").VecModel;
originScreenPoint: import("@tldraw/tlschema").VecModel;
pointerVelocity: import("@tldraw/tlschema").VecModel;
previousPagePoint: import("@tldraw/tlschema").VecModel;
previousScreenPoint: import("@tldraw/tlschema").VecModel;
shiftKey: boolean;
};