InputsManager

See source code
Table of contents

Extends EditorManager.

class InputsManager extends EditorManager {}

Constructor

Constructs a new instance of the InputsManager class

Parameters

NameDescription

editor

Editor;

Properties

accelKey

readonly

Deprecated: Use getAccelKey() instead.

get accelKey(): boolean;

altKey

Deprecated: Use getAltKey() instead.

get altKey(): boolean;

set altKey(altKey: boolean);

buttons

readonly

A set containing the currently pressed buttons.

readonly buttons: AtomSet<number>;

ctrlKey

Deprecated: Use getCtrlKey() instead.

get ctrlKey(): boolean;

set ctrlKey(ctrlKey: boolean);

currentPagePoint

readonly

Deprecated: Use getCurrentPagePoint() instead.

get currentPagePoint(): Vec;

currentScreenPoint

readonly

Deprecated: Use getCurrentScreenPoint() instead.

get currentScreenPoint(): Vec;

disposables

readonly
protected readonly disposables: Set<() => void>;

editor

readonly
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

readonly

A set containing the currently pressed keys.

readonly keys: AtomSet<string>;

metaKey

Deprecated: Use getMetaKey() instead.

get metaKey(): boolean;

set metaKey(metaKey: boolean);

originPagePoint

readonly

Deprecated: Use getOriginPagePoint() instead.

get originPagePoint(): Vec;

originScreenPoint

readonly

Deprecated: Use getOriginScreenPoint() instead.

get originScreenPoint(): Vec;

pointerVelocity

readonly

Deprecated: Use getPointerVelocity() instead.

get pointerVelocity(): Vec;

previousPagePoint

readonly

Deprecated: Use getPreviousPagePoint() instead.

get previousPagePoint(): Vec;

previousScreenPoint

readonly

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

NameDescription

event

E;

fn

(...args: TLEventMap[E]) => void;

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

NameDescription

dispose

() => void;

Returns

() => void;

setIsDragging( )

setIsDragging(isDragging: boolean): void;

Parameters

NameDescription

isDragging

boolean;

Whether the user is dragging.

Returns

void;

setIsEditing( )

setIsEditing(isEditing: boolean): void;

Parameters

NameDescription

isEditing

boolean;

Whether the user is editing.

Returns

void;

setIsPen( )

setIsPen(isPen: boolean): void;

Parameters

NameDescription

isPen

boolean;

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;
};

Prev
HistoryManager
Next
Mat