Viam SDK
    Preparing search index...

    Interface InputController

    Represents a human interface device like a mouse or keyboard that emits events for controls.

    interface InputController {
        name: string;
        doCommand(command: Struct | Record<string, JsonValue>): Promise<JsonValue>;
        getEvents(extra?: Struct): Promise<PlainMessage<Event>[]>;
        getStatus(): Promise<JsonValue>;
        triggerEvent(event: InputControllerEvent, extra?: Struct): Promise<void>;
    }

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    name: string

    The name of the resource.

    Methods

    • Send/Receive arbitrary commands to the resource.

      Parameters

      • command: Struct | Record<string, JsonValue>

        The command to execute. Accepts either a Struct or a plain object, which will be converted automatically.

      Returns Promise<JsonValue>

      // Plain object (recommended)
      const result = await resource.doCommand({
      myCommand: { key: 'value' },
      });

      // Struct (still supported)
      import { Struct } from '@viamrobotics/sdk';

      const result = await resource.doCommand(Struct.fromJson({ myCommand: { key: 'value' } }));
    • Returns a list of events representing the last event on each control.

      Parameters

      Returns Promise<PlainMessage<Event>[]>

      const controller = new VIAM.InputControllerClient(machine, 'my_controller');

      // Get the most recent Event for each Control
      const recentEvents = await controller.getEvents();
      console.log('Recent events:', recentEvents);

      For more information, see Input Controller API.

    • TriggerEvent, where supported, injects an InputControllerEvent into an input controller to (virtually) generate events like button presses or axis movements.

      Parameters

      Returns Promise<void>

      const controller = new VIAM.InputControllerClient(machine, 'my_controller');

      // Create a "Button is Pressed" event for the control BUTTON_START
      const buttonPressEvent = new VIAM.InputControllerEvent({
      time: { seconds: BigInt(Math.floor(Date.now() / 1000)) },
      event: 'ButtonPress',
      control: 'ButtonStart',
      value: 1.0,
      });
      // Trigger the event
      await controller.triggerEvent(buttonPressEvent);

      For more information, see Input Controller API.