UNPKG

toukey

Version:

Toukey is a Javascript library for keyboard shortcuts

78 lines (75 loc) 2.02 kB
type ToukeyOptions = { scope?: string; splitValue?: string; keydown?: boolean; keyup?: boolean; once?: boolean; }; type ToukeyOffOptions = { scope?: string; splitValue?: string; keydown?: boolean; keyup?: boolean; }; type ToukeyHandler = (e: KeyboardEvent) => void; /** * @desc Subscribe the key's keyboard event. * @param {string} key * @param {function} handler - Callback. * @param {string | object} options - If the options is a string. It will be the scope. * @param {string} options.scope * @param {string} options.splitValue * @param {boolean} options.keydown * @param {boolean} options.keyup * @param {boolean} options.once * @returns {function} - Unsubscribe key's keyboard event. */ declare function subscribe(key: string, handler: ToukeyHandler, options?: string | ToukeyOptions): () => void; /** * @desc Return the scope * @returns {string} */ declare function getScope(): string; /** * @desc Set the scope. * @param {string} scope */ declare function setScope(scope: string): void; /** * @desc Delete the scope. But it will not success when the scope is * * @param {string} scope */ declare function deleteScope(scope: string): void; /** * @desc Clear all listener. */ declare function clearAll(): void; /** * @desc Set all listeners enable */ declare function enable(): void; /** * @desc Set all listeners disable */ declare function disable(): void; /** * @desc Return true if toukey is enabled */ declare function isEnabled(): boolean; /** * @desc Subscribe the key's keyboard event. * * @param key * @param handler * @param options */ declare function on(key: string, handler: ToukeyHandler, options?: ToukeyOptions): void; /** * @desc Unsubscribe the key's keyboard event. * * @param key * @param handler * @param options */ declare function off(key: string, handler?: ToukeyHandler, options?: ToukeyOffOptions): void; export { clearAll, deleteScope, disable, enable, getScope, isEnabled, off, on, setScope, subscribe };