UNPKG

@elgato-stream-deck/core

Version:

An npm module for interfacing with the Elgato Stream Deck

34 lines 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ButtonOnlyInputService = void 0; class ButtonOnlyInputService { deviceProperties; #keyState; #eventSource; constructor(deviceProperties, eventSource) { this.deviceProperties = deviceProperties; this.#eventSource = eventSource; const maxButtonIndex = this.deviceProperties.CONTROLS.filter((control) => control.type === 'button').map((control) => control.index); this.#keyState = new Array(Math.max(-1, ...maxButtonIndex) + 1).fill(false); } handleInput(data) { const dataOffset = this.deviceProperties.KEY_DATA_OFFSET || 0; for (const control of this.deviceProperties.CONTROLS) { if (control.type !== 'button') continue; const keyPressed = Boolean(data[dataOffset + control.hidIndex]); const stateChanged = keyPressed !== this.#keyState[control.index]; if (stateChanged) { this.#keyState[control.index] = keyPressed; if (keyPressed) { this.#eventSource.emit('down', control); } else { this.#eventSource.emit('up', control); } } } } } exports.ButtonOnlyInputService = ButtonOnlyInputService; //# sourceMappingURL=gen1.js.map