import ButtonInputControl, { ButtonInputControlOptions } from '../controls/ButtonInputControl'; import { Device, DeviceEvents, DeviceOptions } from '../Device'; import { WildcardHandler } from 'mitt'; export interface KeyboardDeviceOptions extends DeviceOptions { /** * Optionally use layout-independent Key Code instead of * key value string. (default: `true`) * * Key Codes: * https://www.w3.org/TR/uievents-code/#code-value-tables * * If false, use key values: * https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values */ keyCode?: boolean; } export interface KeyboardGetControlOptions extends Omit { /** * filter may be one of the following: * - string: name of code (or key value) * - array of strings: responds to any of the keys in the array * - function: a callback that gets called with a Set of active key names and * is expected to return a boolean, whether or not to respond to the keyboard event. */ filter?: string | string[] | ((keys: Set) => boolean); } type KeyboardEvents = DeviceEvents & { enable: unknown; disable: unknown; }; /** * A Keyboard device. */ export default class Keyboard extends Device { /** * Create a {@link controls/ButtonInputControl.ButtonInputControl | button control} for a single key or combination of keys. * Key names correspond to the [names used by DOM `KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). * * @param name The name of the control. If no `filter` option is provided, this * also specifies which key on the keyboard to use. */ getControl: (name: string, options?: KeyboardGetControlOptions) => ButtonInputControl; on: { /** * Emitted when the Device is set to enabled * @event */ (type: 'enable', handler: () => void): void; /** * Emitted when the Device is set to disabled * @event */ (type: 'disable', handler: () => void): void; /** * Emitted when any value changes. * @event */ (type: 'change', handler: () => void): void; (type: '*', handler: WildcardHandler): void; }; /** * Always true. */ readonly connected: boolean; /** * @param keyboardOptions options */ constructor(keyboardOptions?: KeyboardDeviceOptions); } export {};