@launchmenu/core
Version:
An environment for visual keyboard controlled applets
84 lines • 2.81 kB
TypeScript
import { IKeyEventListener } from "./_types/IKeyEventListener";
import { IKeyHandlerTarget } from "./_types/IKeyHandlerTarget";
import { IKey } from "./_types/IKey";
import { KeyEvent } from "./KeyEvent";
/**
* A key handler class
*/
export declare class KeyHandler {
protected listeners: IKeyEventListener[];
protected pressedKeys: {
[key: string]: IKey;
};
protected keyListener: (event: KeyboardEvent) => void;
protected target: IKeyHandlerTarget;
protected id: number;
/**
* Creates a new key handler for the specified target
* @param target The target to add the listeners to
*/
constructor(target: IKeyHandlerTarget);
/**
* Sets up the listeners for the target
* @param resetOnBlur Whether to reset the pressed keys if the window loses focus
*/
protected setupListeners(): void;
/**
* Emits a given keyboard event
* @param event
*/
emit(event: KeyEvent, { store, insertHeldKeys, }?: {
/** Whether to use the event to alter the held keys */
store?: boolean;
/** Whether to add the held keys to the event */
insertHeldKeys?: boolean;
}): void;
/**
* Fixes some issues with the meta key on windows and mac.
* @param event the key event to handle meta issues for if relevant
*/
protected handleMetaIssues(event: KeyEvent): void;
/**
* Removes the handlers from the target
*/
destroy(): void;
/**
* Releases all currently held keys
*/
resetKeys(): void;
/**
* Checks wether the key with the specified id is pressed
* @param id The id of the key
* @returns Whether the key is pressed
*/
isDown(id: number): boolean;
/**
* Checks wether the key with the specified name is pressed
* @param name The name of the key
* @returns Whether the key is pressed
*/
isDown(name: string): boolean;
/**
* Calls all the listeners with the loaded data
*/
protected callListeners(event: KeyEvent): void;
/**
* Adds a listener to the key handler
* @param listener The listener to add
* @returns This, for method chaining
*/
listen(listener: IKeyEventListener): this;
/**
* Removes a listener from the key handler
* @param listener The listener to remove
* @returns Whether the listener was removed
*/
removeListener(listener: IKeyEventListener): boolean;
/**
* Retrieves the input data for a 'synthetic' key event
* @param event The original event
* @returns The input for the event
*/
static getKeyEvent(event: KeyboardEvent): KeyEvent | null;
}
//# sourceMappingURL=KeyHandler.d.ts.map