From be90a1cfdc6f54e5ed8d27f40138c83426dab640 Mon Sep 17 00:00:00 2001 From: terry feng Date: Tue, 5 Dec 2023 13:22:13 -0800 Subject: [PATCH] Introduce HID, add documentation, clean chuck code --- dist/Hid.d.ts | 39 ++++++++---- dist/Hid.js | 76 ++++++++++++---------- dist/hidCk.d.ts | 4 +- dist/hidCk.js | 61 ++++-------------- docs/assets/search.js | 2 +- docs/classes/Chuck.html | 106 +++++++++++++++---------------- docs/classes/HID.html | 91 ++++++++++---------------- src/Hid.ck | 105 ------------------------------ src/Hid.ts | 109 +++++++++++++++++--------------- src/HidMsg.ck | 71 --------------------- src/hidCk.ts | 61 ++++-------------- src/wc-bundle.js | 137 +++++++++++++++++----------------------- test/chuckTest.js | 5 +- 13 files changed, 306 insertions(+), 561 deletions(-) delete mode 100644 src/Hid.ck delete mode 100644 src/HidMsg.ck diff --git a/dist/Hid.d.ts b/dist/Hid.d.ts index 53b79be..b65813f 100644 --- a/dist/Hid.d.ts +++ b/dist/Hid.d.ts @@ -1,9 +1,20 @@ import Chuck from "./Chuck"; +/** + * Introducing HID (Human Interface Device) support for WebChucK. WebChucK HID + * brings mouse and keyboard support to work with the native {@link https://chuck.stanford.edu/doc/reference/io.html#Hid | Hid} + * class in ChucK. WebChucK HID wraps JavaScript mouse and keyboard event + * listeners. To get started with HID: + * @example + * ```ts + * import { Chuck, HID } from "webchuck"; + * + * const theChuck = await Chuck.init([]); + * const hid = await HID.init(theChuck); + * ``` + */ export default class HID { private theChuck; private keymap; - private mousePos; - private lastPos; private _mouseActive; private _kbdActive; private boundHandleMouseMove; @@ -20,12 +31,12 @@ export default class HID { * Mouse and keyboard event listeners are added if `enableMouse` and `enableKeyboard` are true (default). * @example * ```ts - * theChuck = await Chuck.init(); // Initialize WebChucK + * theChuck = await Chuck.init([]); * hid = await HID.init(theChuck); // Initialize HID with mouse and keyboard * ``` * @example * ```ts - * theChuck = await Chuck.init(); // Initialize WebChucK + * theChuck = await Chuck.init([]); * hid = await HID.init(theChuck, false, true); // Initialize HID, no mouse, only keyboard * ``` * @param theChuck WebChucK instance @@ -54,7 +65,7 @@ export default class HID { y: number; }; /** - * Enable Mouse HID Javascript event listeners to communicate with ChucK + * Enable Mouse HID Javascript event listeners for Chuck HID * Adds a mousemove, mousedown, mouseup, and wheel listener to the document. * @example * ```ts @@ -73,7 +84,7 @@ export default class HID { */ disableMouse(): void; /** - * Enable keyboard HID Javascript event listeners to communicate with ChucK. + * Enable keyboard HID Javascript event listeners for Chuck HID * Adds a keydown and keyup listener to the document. * @example * ```ts @@ -92,22 +103,24 @@ export default class HID { */ disableKeyboard(): void; /** @internal */ - handleMouseMove(e: MouseEvent): void; + private handleMouseMove; /** @internal */ - handleMouseDown(e: MouseEvent): void; + private handleMouseDown; /** @internal */ - handleMouseUp(e: MouseEvent): void; + private handleMouseUp; /** @internal */ - handleMouseWheel(e: WheelEvent): void; + private handleMouseWheel; /** @internal */ - handleKeyDown(e: KeyboardEvent): void; + private static handleContextMenu; /** @internal */ - handleKeyUp(e: KeyboardEvent): void; + private handleKeyDown; + /** @internal */ + private handleKeyUp; /** * @internal * Handle keyboard presses to send to chuck * @param e Keyboard event * @param isDown Is key down */ - keyPressManager(e: KeyboardEvent, isDown: boolean): void; + private keyPressManager; } diff --git a/dist/Hid.js b/dist/Hid.js index cad4ef1..da65e86 100644 --- a/dist/Hid.js +++ b/dist/Hid.js @@ -1,4 +1,24 @@ import { Hid_ck, HidMsg_ck } from "./hidCk"; +var HidMsgType; +(function (HidMsgType) { + HidMsgType[HidMsgType["BUTTON_DOWN"] = 1] = "BUTTON_DOWN"; + HidMsgType[HidMsgType["BUTTON_UP"] = 2] = "BUTTON_UP"; + HidMsgType[HidMsgType["MOUSE_MOTION"] = 5] = "MOUSE_MOTION"; + HidMsgType[HidMsgType["WHEEL_MOTION"] = 6] = "WHEEL_MOTION"; +})(HidMsgType || (HidMsgType = {})); +/** + * Introducing HID (Human Interface Device) support for WebChucK. WebChucK HID + * brings mouse and keyboard support to work with the native {@link https://chuck.stanford.edu/doc/reference/io.html#Hid | Hid} + * class in ChucK. WebChucK HID wraps JavaScript mouse and keyboard event + * listeners. To get started with HID: + * @example + * ```ts + * import { Chuck, HID } from "webchuck"; + * + * const theChuck = await Chuck.init([]); + * const hid = await HID.init(theChuck); + * ``` + */ export default class HID { /** @internal */ constructor(theChuck) { @@ -7,8 +27,6 @@ export default class HID { // Initialize members this.theChuck = theChuck; this.keymap = new Array(256).fill(false); - this.mousePos = { x: 0, y: 0 }; - this.lastPos = { x: 0, y: 0 }; // Bind handlers this.boundHandleMouseMove = this.handleMouseMove.bind(this); this.boundHandleMouseDown = this.handleMouseDown.bind(this); @@ -23,12 +41,12 @@ export default class HID { * Mouse and keyboard event listeners are added if `enableMouse` and `enableKeyboard` are true (default). * @example * ```ts - * theChuck = await Chuck.init(); // Initialize WebChucK + * theChuck = await Chuck.init([]); * hid = await HID.init(theChuck); // Initialize HID with mouse and keyboard * ``` * @example * ```ts - * theChuck = await Chuck.init(); // Initialize WebChucK + * theChuck = await Chuck.init([]); * hid = await HID.init(theChuck, false, true); // Initialize HID, no mouse, only keyboard * ``` * @param theChuck WebChucK instance @@ -78,7 +96,7 @@ export default class HID { }; } /** - * Enable Mouse HID Javascript event listeners to communicate with ChucK + * Enable Mouse HID Javascript event listeners for Chuck HID * Adds a mousemove, mousedown, mouseup, and wheel listener to the document. * @example * ```ts @@ -91,6 +109,7 @@ export default class HID { document.addEventListener("mousedown", this.boundHandleMouseDown); document.addEventListener("mouseup", this.boundHandleMouseUp); document.addEventListener("wheel", this.boundHandleMouseWheel); + document.addEventListener("contextmenu", HID.handleContextMenu); } /** * Disable Mouse HID Javascript event listeners @@ -105,9 +124,10 @@ export default class HID { document.removeEventListener("mousedown", this.boundHandleMouseDown); document.removeEventListener("mouseup", this.boundHandleMouseUp); document.removeEventListener("wheel", this.boundHandleMouseWheel); + document.removeEventListener("contextmenu", HID.handleContextMenu); } /** - * Enable keyboard HID Javascript event listeners to communicate with ChucK. + * Enable keyboard HID Javascript event listeners for Chuck HID * Adds a keydown and keyup listener to the document. * @example * ```ts @@ -139,55 +159,47 @@ export default class HID { handleMouseMove(e) { this.mouseActive(); if (this._mouseActive) { - this.mousePos = this.getMousePos(e); - this.theChuck.setInt("_mouseMotion", 1); - this.theChuck.broadcastEvent("_hid"); - this.theChuck.setInt("_mouseX", this.mousePos.x); - this.theChuck.setInt("_mouseY", this.mousePos.y); + const mousePos = this.getMousePos(e); this.theChuck.setFloat("_deltaX", e.movementX); this.theChuck.setFloat("_deltaY", e.movementY); - this.theChuck.setFloat("_scaledCursorX", this.mousePos.x / document.documentElement.clientWidth); - this.theChuck.setFloat("_scaledCursorY", this.mousePos.y / document.documentElement.clientHeight); - this.theChuck.broadcastEvent("_msg"); + this.theChuck.setFloat("_scaledCursorX", mousePos.x / document.documentElement.clientWidth); + this.theChuck.setFloat("_scaledCursorY", mousePos.y / document.documentElement.clientHeight); + this.theChuck.setInt("_type", HidMsgType.MOUSE_MOTION); + this.theChuck.broadcastEvent("_hid"); } - this.lastPos = this.mousePos; } /** @internal */ handleMouseDown(e) { this.mouseActive(); if (this._mouseActive) { - this.theChuck.setInt("_mouseMotion", 0); - this.theChuck.setInt("_mouseDown", 1); - this.theChuck.broadcastEvent("_hid"); - this.theChuck.setInt("_hidMouse", 1); this.theChuck.setInt("_which", e.which); - this.theChuck.broadcastEvent("_msg"); + this.theChuck.setInt("_type", HidMsgType.BUTTON_DOWN); + this.theChuck.broadcastEvent("_hid"); } } /** @internal */ handleMouseUp(e) { this.mouseActive(); if (this._mouseActive) { - this.theChuck.setInt("_mouseMotion", 0); - this.theChuck.setInt("_mouseUp", 1); - this.theChuck.broadcastEvent("_hid"); - this.theChuck.setInt("_hidMouse", 1); this.theChuck.setInt("_which", e.which); - this.theChuck.broadcastEvent("_msg"); + this.theChuck.setInt("_type", HidMsgType.BUTTON_UP); + this.theChuck.broadcastEvent("_hid"); } } /** @internal */ handleMouseWheel(e) { this.mouseActive(); if (this._mouseActive) { - this.theChuck.setInt("_mouseMotion", 0); - this.theChuck.setInt("_isScroll", 1); - this.theChuck.setInt("_deltaX", clamp(e.deltaX, -1, 1)); - this.theChuck.setInt("_deltaY", clamp(e.deltaY, -1, 1)); + this.theChuck.setFloat("_deltaX", clamp(e.deltaX, -1, 1)); + this.theChuck.setFloat("_deltaY", clamp(e.deltaY, -1, 1)); + this.theChuck.setInt("_type", HidMsgType.WHEEL_MOTION); this.theChuck.broadcastEvent("_hid"); - this.theChuck.broadcastEvent("_msg"); } } + /** @internal */ + static handleContextMenu(e) { + e.preventDefault(); + } //----------- KEYBOARD --------- // /** @internal */ handleKeyDown(e) { @@ -215,7 +227,7 @@ export default class HID { this.theChuck.setString("_key", e.key); this.theChuck.setInt("_which", e.which); this.theChuck.setInt("_ascii", e.keyCode); - this.theChuck.setInt("_type", isDown ? 1 : 2); + this.theChuck.setInt("_type", isDown ? HidMsgType.BUTTON_DOWN : HidMsgType.BUTTON_UP); this.theChuck.broadcastEvent("_hid"); } } @@ -227,7 +239,7 @@ export default class HID { * @param val value to clamp * @param min min value * @param max max value - * @returns clamp value + * @returns clamped value */ function clamp(val, min, max) { return Math.min(Math.max(val, min), max); diff --git a/dist/hidCk.d.ts b/dist/hidCk.d.ts index 06bcb8a..3e1cb8c 100644 --- a/dist/hidCk.d.ts +++ b/dist/hidCk.d.ts @@ -1,3 +1,3 @@ -declare const HidMsg_ck = "\nglobal Event _msg;\n \nglobal Event _hid;\nglobal int _hidMultiple;\n0 => global int _cursorX;\n0 => global int _cursorY;\n\n0 => global float _deltaX;\n0 => global float _deltaY;\n\nglobal string _key;\nglobal int _isDown;\nglobal int _isUp;\nglobal int _isMouseDown;\nglobal int _isMouseUp;\nglobal int _isScroll;\nglobal int _ascii;\nglobal int _which;\nglobal int _mouseActive;\nglobal int _kbdActive;\nglobal int _mouseMotion;\nglobal float _scaledCursorX;\nglobal float _scaledCursorY;\n\npublic class HidMsg {\n int type;\n int deviceType;\n int cursorX;\n int cursorY;\n float deltaX;\n float deltaY;\n float scaledCursorX;\n float scaledCursorY;\n int which;\n int ascii;\n string key;\n\n // type 1 message\n function int isButtonDown() {\n if (type == 1) { return 1; }\n return 0;\n }\n\n // type 2 message\n function int isButtonUp() {\n if (type == 2) { return 1; }\n return 0;\n }\n\n // type 5 message\n function int isMouseMotion(){\n if (type == 5) { return 1; }\n return 0;\n }\n\n // type 6 message\n function int isWheelMotion(){\n if (type == 6) { return 1; }\n return 0;\n }\n\n function void _copy(HidMsg localMsg) {\n localMsg.type => type;\n localMsg.deviceType => deviceType;\n localMsg.cursorX => cursorX;\n localMsg.cursorY => cursorY;\n localMsg.deltaX => deltaX;\n localMsg.deltaY => deltaY;\n localMsg.scaledCursorX => scaledCursorX;\n localMsg.scaledCursorY => scaledCursorY;\n localMsg.which => which;\n localMsg.ascii => ascii;\n localMsg.key => key;\n }\n}\n"; -declare const Hid_ck = "\nglobal Event _msg;\n\nglobal Event _hid;\nglobal int _cursorX;\nglobal int _cursorY;\n\nglobal float _deltaX;\nglobal float _deltaY;\n\nglobal int _type;\nglobal string _key;\nglobal int _isDown;\nglobal int _isUp;\nglobal int _isMouseDown;\nglobal int _isMouseUp;\nglobal int _isScroll;\nglobal int _ascii;\nglobal int _which;\nglobal int _mouseActive;\nglobal int _kbdActive;\nglobal int _mouseMotion;\nglobal float _scaledCursorX;\nglobal float _scaledCursorY;\n\npublic class Hid extends Event {\n\n 0 => int isMouseOpen;\n 0 => int isKBDOpen;\n 0 => int active;\n\n string deviceName; \n int deviceType; // mouse = 2, keyboard = 3\n\n // HidMsg Queue\n HidMsg _hidMsgQueue[0];\n\n function string name() {\n return deviceName;\n }\n\n function int openMouse(int num) {\n if (num < 0) {\n false => active;\n } else {\n \"virtualJS mouse/trackpad\" => deviceName;\n 2 => deviceType;\n true => active;\n }\n active => isMouseOpen => _mouseActive;\n return active;\n }\n\n function int openKeyboard(int num) {\n if (num < 0) {\n false => active;\n } else {\n \"virtualJS keyboard\" => deviceName;\n 3 => deviceType;\n true => active;\n }\n active => isKBDOpen => _kbdActive;\n return active;\n }\n\n // Pop the first HidMsg from the queue\n // Write it to msg and return 1\n function int recv(HidMsg msg) {\n // is empty\n if (_hidMsgQueue.size() <= 0) {\n return 0;\n }\n\n // pop the first HidMsg to msg, return true\n _hidMsgQueue[0] @=> HidMsg localMsg;\n msg._copy(localMsg); \n _hidMsgQueue.popFront();\n return 1;\n }\n\n // Hid Listener\n // Get variables from JS and write to the HidMsg \n function void _HidListener() {\n HidMsg @ msg;\n while(true){\n new HidMsg @=> msg;\n deviceType => msg.deviceType;\n _hid => now;\n\n _type => msg.type;\n _cursorX => msg.cursorX;\n _cursorY => msg.cursorY;\n _deltaX => msg.deltaX;\n _deltaY => msg.deltaY;\n _scaledCursorX => msg.scaledCursorX;\n _scaledCursorY => msg.scaledCursorY;\n _which => msg.which;\n _ascii => msg.ascii;\n _key => msg.key;\n\n _hidMsgQueue << msg;\n this.broadcast();\n }\n }\n spork ~ _HidListener();\n}\n"; +declare const HidMsg_ck = "\npublic class HidMsg {\n int type;\n int deviceType;\n int cursorX;\n int cursorY;\n float deltaX;\n float deltaY;\n float scaledCursorX;\n float scaledCursorY;\n int which;\n int ascii;\n string key;\n\n // type 1 message\n function int isButtonDown() {\n return type == 1;\n }\n\n // type 2 message\n function int isButtonUp() {\n return type == 2;\n }\n\n // type 5 message\n function int isMouseMotion(){\n return type == 5;\n }\n\n // type 6 message\n function int isWheelMotion(){\n return type == 6;\n }\n\n function void _copy(HidMsg localMsg) {\n localMsg.type => type;\n localMsg.deviceType => deviceType;\n localMsg.cursorX => cursorX;\n localMsg.cursorY => cursorY;\n localMsg.deltaX => deltaX;\n localMsg.deltaY => deltaY;\n localMsg.scaledCursorX => scaledCursorX;\n localMsg.scaledCursorY => scaledCursorY;\n localMsg.which => which;\n localMsg.ascii => ascii;\n localMsg.key => key;\n }\n}\n"; +declare const Hid_ck = "\nglobal Event _hid;\nglobal int _type;\nglobal int _mouseActive;\nglobal int _kbdActive;\n\nglobal int _cursorX;\nglobal int _cursorY;\nglobal float _deltaX;\nglobal float _deltaY;\nglobal float _scaledCursorX;\nglobal float _scaledCursorY;\n\nglobal int _ascii;\nglobal int _which;\nglobal string _key;\n\npublic class Hid extends Event {\n\n 0 => int isMouseOpen;\n 0 => int isKBDOpen;\n 0 => int active;\n\n string deviceName; \n int deviceType; // mouse = 2, keyboard = 3\n\n // HidMsg Queue\n HidMsg _hidMsgQueue[0];\n\n function string name() {\n return deviceName;\n }\n\n function int openMouse(int num) {\n if (num < 0) {\n false => active;\n } else {\n \"virtualJS mouse/trackpad\" => deviceName;\n 2 => deviceType;\n true => active;\n }\n active => isMouseOpen => _mouseActive;\n return active;\n }\n\n function int openKeyboard(int num) {\n if (num < 0) {\n false => active;\n } else {\n \"virtualJS keyboard\" => deviceName;\n 3 => deviceType;\n true => active;\n }\n active => isKBDOpen => _kbdActive;\n return active;\n }\n\n // Pop the first HidMsg from the queue\n // Write it to msg and return 1\n function int recv(HidMsg msg) {\n // is empty\n if (_hidMsgQueue.size() <= 0) {\n return 0;\n }\n\n // pop the first HidMsg to msg, return true\n _hidMsgQueue[0] @=> HidMsg localMsg;\n msg._copy(localMsg); \n _hidMsgQueue.popFront();\n return 1;\n }\n\n // Hid Listener\n // Get variables from JS and write to the HidMsg \n function void _HidListener() {\n HidMsg @ msg;\n while(true){\n new HidMsg @=> msg;\n deviceType => msg.deviceType;\n _hid => now;\n\n _type => msg.type;\n _cursorX => msg.cursorX;\n _cursorY => msg.cursorY;\n _deltaX => msg.deltaX;\n _deltaY => msg.deltaY;\n _scaledCursorX => msg.scaledCursorX;\n _scaledCursorY => msg.scaledCursorY;\n _which => msg.which;\n _ascii => msg.ascii;\n _key => msg.key;\n\n _hidMsgQueue << msg;\n this.broadcast();\n\n // Clear message type\n 0 => _type;\n }\n }\n spork ~ _HidListener();\n}\n"; export { HidMsg_ck, Hid_ck }; diff --git a/dist/hidCk.js b/dist/hidCk.js index 18e7e53..62c99c8 100644 --- a/dist/hidCk.js +++ b/dist/hidCk.js @@ -1,28 +1,4 @@ const HidMsg_ck = ` -global Event _msg; - -global Event _hid; -global int _hidMultiple; -0 => global int _cursorX; -0 => global int _cursorY; - -0 => global float _deltaX; -0 => global float _deltaY; - -global string _key; -global int _isDown; -global int _isUp; -global int _isMouseDown; -global int _isMouseUp; -global int _isScroll; -global int _ascii; -global int _which; -global int _mouseActive; -global int _kbdActive; -global int _mouseMotion; -global float _scaledCursorX; -global float _scaledCursorY; - public class HidMsg { int type; int deviceType; @@ -38,26 +14,22 @@ public class HidMsg { // type 1 message function int isButtonDown() { - if (type == 1) { return 1; } - return 0; + return type == 1; } // type 2 message function int isButtonUp() { - if (type == 2) { return 1; } - return 0; + return type == 2; } // type 5 message function int isMouseMotion(){ - if (type == 5) { return 1; } - return 0; + return type == 5; } // type 6 message function int isWheelMotion(){ - if (type == 6) { return 1; } - return 0; + return type == 6; } function void _copy(HidMsg localMsg) { @@ -76,29 +48,21 @@ public class HidMsg { } `; const Hid_ck = ` -global Event _msg; - global Event _hid; +global int _type; +global int _mouseActive; +global int _kbdActive; + global int _cursorX; global int _cursorY; - global float _deltaX; global float _deltaY; +global float _scaledCursorX; +global float _scaledCursorY; -global int _type; -global string _key; -global int _isDown; -global int _isUp; -global int _isMouseDown; -global int _isMouseUp; -global int _isScroll; global int _ascii; global int _which; -global int _mouseActive; -global int _kbdActive; -global int _mouseMotion; -global float _scaledCursorX; -global float _scaledCursorY; +global string _key; public class Hid extends Event { @@ -177,6 +141,9 @@ public class Hid extends Event { _hidMsgQueue << msg; this.broadcast(); + + // Clear message type + 0 => _type; } } spork ~ _HidListener(); diff --git a/docs/assets/search.js b/docs/assets/search.js index ad3f2fb..5f62a0e 100644 --- a/docs/assets/search.js +++ b/docs/assets/search.js @@ -1 +1 @@ -window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAAE72bW2+jyBLHv4v31eNN38DJ22jmzNnR7upEZ7W7D1YUEZvYKDZYQG6K5rtvd2PsKqhuM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pkvKChmWuVKwavciAL6cqiGLjKgciEJ7LuKgcQcBeCwrnKAW0xSLsbORg6wjV0iu4qBxLmnoTJVQ4UXngK76423GS6xmvhXOVA6NITOrnKAc+yzzOxygFe0sOrq8kBJu7EZD9O6t56gbmYu+Zi+wVO0nwF06wHyAzInTtzL7OD3wqYA7hrDih3UedWUAFFRWK7m88O8SFK4lQLre7e3v4Fxz7QE3s+AAA="; \ No newline at end of file diff --git a/docs/classes/Chuck.html b/docs/classes/Chuck.html index 8f947ec..879d733 100644 --- a/docs/classes/Chuck.html +++ b/docs/classes/Chuck.html @@ -27,7 +27,7 @@

Hierarchy

+
  • Defined in src/Chuck.ts:30
  • @@ -145,34 +145,34 @@

    Returns

    +
  • Defined in src/Chuck.ts:48
  • Properties

    deferredPromises: DeferredPromisesMap = {}
    +
  • Defined in src/Chuck.ts:31
  • deferredPromiseCounter: number = 0
    +
  • Defined in src/Chuck.ts:32
  • eventCallbacks: EventCallbacksMap = {}
    +
  • Defined in src/Chuck.ts:33
  • eventCallbackCounter: number = 0
    +
  • Defined in src/Chuck.ts:34
  • isReady: default<void> = ...
    +
  • Defined in src/Chuck.ts:35
  • onprocessorerror: null | ((this, ev) => any)
    @@ -291,7 +291,7 @@

    Example

    // Initialize
     
    +
  • Defined in src/Chuck.ts:108
  • +
  • Defined in src/Chuck.ts:146
  • +
  • Defined in src/Chuck.ts:161
  • +
  • Defined in src/Chuck.ts:177
  • +
  • Defined in src/Chuck.ts:207
  • +
  • Defined in src/Chuck.ts:237
  • +
  • Defined in src/Chuck.ts:276
  • +
  • Defined in src/Chuck.ts:296
  • +
  • Defined in src/Chuck.ts:331
  • +
  • Defined in src/Chuck.ts:371
  • +
  • Defined in src/Chuck.ts:414
  • +
  • Defined in src/Chuck.ts:463
  • +
  • Defined in src/Chuck.ts:477
  • +
  • Defined in src/Chuck.ts:491
  • +
  • Defined in src/Chuck.ts:499
  • +
  • Defined in src/Chuck.ts:510
  • +
  • Defined in src/Chuck.ts:528
  • +
  • Defined in src/Chuck.ts:544
  • +
  • Defined in src/Chuck.ts:558
  • +
  • Defined in src/Chuck.ts:568
  • +
  • Defined in src/Chuck.ts:582
  • +
  • Defined in src/Chuck.ts:591
  • +
  • Defined in src/Chuck.ts:605
  • +
  • Defined in src/Chuck.ts:614
  • +
  • Defined in src/Chuck.ts:629
  • +
  • Defined in src/Chuck.ts:638
  • +
  • Defined in src/Chuck.ts:653
  • +
  • Defined in src/Chuck.ts:667
  • +
  • Defined in src/Chuck.ts:685
  • +
  • Defined in src/Chuck.ts:700
  • +
  • Defined in src/Chuck.ts:716
  • +
  • Defined in src/Chuck.ts:726
  • +
  • Defined in src/Chuck.ts:741
  • +
  • Defined in src/Chuck.ts:756
  • +
  • Defined in src/Chuck.ts:774
  • +
  • Defined in src/Chuck.ts:789
  • +
  • Defined in src/Chuck.ts:806
  • +
  • Defined in src/Chuck.ts:815
  • +
  • Defined in src/Chuck.ts:829
  • +
  • Defined in src/Chuck.ts:837
  • +
  • Defined in src/Chuck.ts:851
  • +
  • Defined in src/Chuck.ts:860
  • +
  • Defined in src/Chuck.ts:874
  • +
  • Defined in src/Chuck.ts:884
  • +
  • Defined in src/Chuck.ts:891
  • +
  • Defined in src/Chuck.ts:912
    • diff --git a/docs/classes/HID.html b/docs/classes/HID.html index e6ad8e5..9fdf922 100644 --- a/docs/classes/HID.html +++ b/docs/classes/HID.html @@ -15,12 +15,23 @@
    • webchuck
    • HID

    Class HID

    +
    +

    Introducing HID (Human Interface Device) support for WebChucK. HID wraps +JavaScript mouse/keyboard event listeners enabling mouse and keyboard +communication with the native 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
    +
  • Defined in src/Hid.ts:27
  • @@ -30,9 +41,6 @@
    theChuck keymap -keysPressed -mousePos -lastPos _mouseActive _kbdActive boundHandleMouseMove @@ -56,51 +64,22 @@

    Properties

    theChuck: Chuck
    +
  • Defined in src/Hid.ts:29
  • keymap: boolean[]
    -
    - -
    keysPressed: number = 0
    -
    - -
    mousePos: {
        x: number;
        y: number;
    }
    -
    -

    Type declaration

    -
      -
    • -
      x: number
    • -
    • -
      y: number
    -
    - -
    lastPos: {
        x: number;
        y: number;
    }
    -
    -

    Type declaration

    -
      -
    • -
      x: number
    • -
    • -
      y: number
    +
  • Defined in src/Hid.ts:30
  • _mouseActive: boolean = false
    +
  • Defined in src/Hid.ts:31
  • _kbdActive: boolean = false
    +
  • Defined in src/Hid.ts:32
  • boundHandleMouseMove: {}
    @@ -110,7 +89,7 @@

    Type declaration

    • +
    • Defined in src/Hid.ts:35
    • boundHandleMouseDown: {}
      @@ -120,7 +99,7 @@

      Type declaration

      • +
      • Defined in src/Hid.ts:36
      • boundHandleMouseUp: {}
        @@ -130,7 +109,7 @@

        Type declaration

        • +
        • Defined in src/Hid.ts:37
        • boundHandleMouseWheel: {}
          @@ -140,7 +119,7 @@

          Type declaration

          • +
          • Defined in src/Hid.ts:38
          • boundHandleKeyDown: {}
            @@ -150,7 +129,7 @@

            Type declaration

            • +
            • Defined in src/Hid.ts:39
            • boundHandleKeyUp: {}
              @@ -160,7 +139,7 @@

              Type declaration

              • +
              • Defined in src/Hid.ts:40
              • Methods

                @@ -168,7 +147,7 @@
                +
              • Defined in src/Hid.ts:75
                • -

                  Enable Mouse HID Javascript event listeners to communicate with ChucK -Adds a mousemove, mousedown, mouseup, and wheel listener to the document.

                  +

                  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

                  @@ -214,7 +194,7 @@

                  Example

                  // If mouse HI
                   
                +
              • Defined in src/Hid.ts:136
                • @@ -228,13 +208,13 @@

                  Example

                  // If mouse HI
                   
                +
              • Defined in src/Hid.ts:152
                • -

                  Enable keyboard HID Javascript event listeners to communicate with ChucK. +

                  Enable keyboard HID Javascript event listeners for HID. Adds a keydown and keyup listener to the document.

                  Returns void

                  @@ -243,7 +223,7 @@

                  Example

                  // If keyboard
                   
                +
              • Defined in src/Hid.ts:169
                • @@ -257,7 +237,7 @@

                  Example

                  // If keyboard
                   
                +
              • Defined in src/Hid.ts:182