Skip to content

textmode.js / Textmodifier / once

Method: once() ​

ts
once<K>(event, handler): () => void;

Register an input event listener that removes itself after the first invocation.

Type Parameters ​

Type ParameterDescription
K extends | keyof KeyboardEventMap | keyof MouseEventMap | keyof TouchEventMap | keyof GamepadEventMapEvent name from the InputEventMap.

Parameters ​

ParameterTypeDescription
eventKThe event to listen for.
handlerInputEventMap[K]The callback to invoke once.

Returns ​

A dispose function that removes the listener before it fires (if needed).

() => void

Example ​

ts
t.once('keyPressed', (data) => {
  console.log('First key press was:', data.key);
});