@launchmenu/core
Version:
An environment for visual keyboard controlled applets
94 lines • 4.39 kB
TypeScript
import { IKeyArrayPatternData } from "../../menus/items/inputs/handlers/keyPattern/_types/IKeyPatternData";
import { KeyPattern } from "../KeyPattern";
import { GlobalKeyboardListener, IGlobalKeyListener as IGKL, IGlobalKey as IGK, IGlobalKeyEvent as IGKE } from "node-global-key-listener";
import { IGlobalKeyListener } from "../_types/IGlobalKeyListener";
import { IGlobalKeyEvent } from "../_types/IGlobalKeyEvent";
import { IDataHook, IDataRetriever, Observer } from "model-react";
/** A class that can be used for registering keyboard shortcuts. Should be used as a singleton obtained from LaunchMenu */
export declare class GlobalKeyHandler {
protected advancedManager: GlobalKeyboardListener | undefined;
protected invokeListeners?: IGKL;
protected keyListeners: IGlobalKeyListener[];
protected electronListeners: Record<string, (() => void)[]>;
protected silentError: boolean;
protected disposed: boolean;
protected useElectronListener: IDataRetriever<boolean>;
protected useElectronListenerObserver: Observer<boolean>;
protected currentUseElectronListener: boolean;
protected shortcutListeners: {
shortcut: KeyPattern;
callback: () => void;
dispose: () => void;
}[];
/**
* Creates a new instance of the global key handler
* @param useElectronListener A data retriever to determine whether to force use electron's listener
*/
constructor(useElectronListener?: IDataRetriever<boolean>);
/**
* Adds a global key listeners that listens to all events
* @param callback The key press callback
* @returns A function that can be invoked to remove the listener
*/
addListener(callback: IGlobalKeyListener): () => void;
/**
* Converts a global key event to the format as used by LM
* @param event The event to convert
* @param held The keys that are currently held
* @returns The LM event
*/
protected convertKeyEvent(event: IGKE, held: {
[K in IGK]?: boolean;
}): IGlobalKeyEvent | undefined;
/**
* Checks whether global key listeners are supported on the current OS/environment
* @param hook The hook to subscribe to changes
* @returns Whether listeners are supported
*/
areListenersSupported(hook?: IDataHook): boolean;
/**
* Sets up an observer that takes care of moving the shortcut listeners if the setting changed
*/
protected setupShortcutMethodObserver(): Observer<boolean>;
/**
* Adds a global shortcut
* @param shortcut The keypattern to listen for
* @param callback The callback to trigger when the event is fired
* @returns A function that can be invoked to remove the shortcut
*/
addShortcut(shortcut: KeyPattern, callback: () => void): () => void;
/**
* Checks whether the given keypattern is valid as a global shortcut or not
* @param shortcut The key pattern to check
* @returns False if the pattern is valid, or the patterns and errors if invalid
*/
isShortcutInvalid(shortcut: KeyPattern): {
pattern: IKeyArrayPatternData;
error: Error;
}[] | false;
/**
* Adds a global shortcut using the node-global-key-listener package
* @param shortcut The key pattern to listen for
* @param callback The callback to trigger when the event is fired
* @returns A function that can be invoked to remove the shortcut
*/
protected addCustomShortcut(shortcut: KeyPattern, callback: () => void): () => void;
/**
* Adds a global shortcut using electron's shortcut system
* @param shortcut The key pattern to listen for
* @param callback The callback to trigger when the event is fired
* @returns A function that can be invoked to remove the shortcut
*/
protected addElectronShortcut(shortcut: KeyPattern, callback: () => void): () => void;
/**
* Retrieves the electron accelerator string if valid, or an error object otherwise
* @param shortcut The key pattern shortcut
* @returns The accelerator string or error object
*/
protected getElectronAccelerators(shortcut: KeyPattern): (string | Error)[];
/**
* Disposes all listeners
*/
destroy(): void;
}
//# sourceMappingURL=GlobalKeyHandler.d.ts.map