v0.7.1 (build 925)

Subscribe to engine- and input-level events emitted by the runtime and compositor.

Pointer interaction subscriptions use Helix/Input and UI virtual handlers; see /helix-input. The event bus continues to deliver keyboard, text and lifecycle events.

Import #

import * as Event from 'Helix/Event';

Functions #

on
Subscribes a callback to an event key. Duplicate subscriptions of the same function are ignored.
on(key: string, callback: (data: any): void) : void
off
Removes a specific callback for the given key, or clears all callbacks if no callback is provided.
off(key: string, callback?: (data: any): void) : void

Emitted events #

EventPayloadDescription
ready{}Emitted once after the bootstrap module is loaded and before the main loop runs.
keyDown{ key: number, time: number, id: number }Emitted when a key is pressed. key is the Linux evdev code. id is the window ID.
keyUp{ key: number, time: number, id: number }Emitted when a key is released.
keyRepeat{ key: number, time: number, id: number }Emitted while a held key repeats using compositor-provided repeat rate/delay.
textInput{ text: string, id: number }Text input after layout/compose via xkbcommon.
textRepeat{ text: string, id: number }Composed text emitted during held-key repeat.
keyModifiers{ depressed: number, latched: number, locked: number, group: number, id: number }Emitted when the keyboard modifier state changes.

Notes #

  • To receive pointer events, create your window with { acceptPointerEvents: true } or call Compositor.setPointerEvents(win, true).

Example #

Subscribe to the most common event bus channels: the one-shot ready event for initialisation, keyboard events for hotkeys, composed text input for typing, and pointer buttons for click handling.

import * as Event from 'Helix/Event';

Event.on('ready', () => {
  console.log('Engine is ready');
});

Event.on('keyDown', ({ key, time }) => {
  console.log('Down:', key, 'at', time);
});

Event.on('keyRepeat', ({ key, time }) => {
  console.log('Repeat:', key, 'at', time);
});

Event.on('textInput', ({ text }) => {
  console.log('Typed:', text);
});

Event.on('textRepeat', ({ text }) => {
  console.log('Repeat text:', text);
});