Class HID

HID (Human Interface Device) support for WebChucK. HID wraps JavaScript mouse/keyboard event listeners enabling mouse and keyboard input via the HID class in ChucK.

To get started with HID:

Example

import { Chuck, HID } from "webchuck";

const theChuck = await Chuck.init([]);
const hid = await HID.init(theChuck); // Initialize HID with mouse and keyboard

Hierarchy

  • HID

Properties

theChuck: Chuck
keymap: boolean[]
_mouseActive: boolean = false
_kbdActive: boolean = false
boundHandleMouseMove: {}

Type declaration

    boundHandleMouseDown: {}

    Type declaration

      boundHandleMouseUp: {}

      Type declaration

        boundHandleMouseWheel: {}

        Type declaration

          boundHandleKeyDown: {}

          Type declaration

            boundHandleKeyUp: {}

            Type declaration

              Methods

              • Initialize HID functionality in your WebChucK instance. This adds a Hid and HidMsg class to the ChucK Virtual Machine (VM). Mouse and keyboard event listeners are added if enableMouse and enableKeyboard are true (default).

                Parameters

                • theChuck: Chuck

                  WebChucK instance

                • enableMouse: boolean = true

                  boolean to enable mouse HID

                • enableKeyboard: boolean = true

                  boolean to enable keyboard HID

                Returns Promise<HID>

                Example

                theChuck = await Chuck.init([]);
                hid = await HID.init(theChuck); // Initialize HID with mouse and keyboard

                Example

                theChuck = await Chuck.init([]);
                hid = await HID.init(theChuck, false, true); // Initialize HID, no mouse, only keyboard
              • Enable Mouse HID Javascript event listeners for HID. Adds a mousemove, mousedown, mouseup, and wheel listener to the document. This will also disable the context menu on right click.

                Returns void

                Example

                // If mouse HID is not yet enabled
                hid.enableMouse();
              • Disable Mouse HID Javascript event listeners

                Returns void

                Example

                // If mouse HID is enabled
                hid.disableMouse();
              • Enable keyboard HID Javascript event listeners for HID. Adds a keydown and keyup listener to the document.

                Returns void

                Example

                // If keyboard HID is not yet enabled
                hid.enableKeyboard();
              • Disable keyboard HID javascript event listeners

                Returns void

                Example

                // If keyboard HID is enabled
                hid.disableKeyboard();