modern-hotkeys
Version:
<p align="center"> <img src="https://img.shields.io/npm/l/modern-hotkeys"> <img src="https://img.shields.io/npm/dt/modern-hotkeys"> <img src="https://img.shields.io/npm/v/modern-hotkeys"> <img src="https://img.shields.io/github/stars/pato12/modern-hotkeys
39 lines (38 loc) • 1.49 kB
TypeScript
import { KeyboardLayout } from './layouts';
import type { HotkeysHandler, TriggerEvent } from './type';
interface HotkeysParams {
element: HTMLElement;
keyboard?: KeyboardLayout;
autoWatchKeys?: boolean;
autoPreventDefault?: boolean;
watchCaps?: boolean;
}
declare type HotkeysCallback = {
unbind: () => void;
};
declare type HotkeysOptions = {
scope?: string;
order?: number;
event?: TriggerEvent;
};
declare function createHotkeys({ element, keyboard: defaultKeyboard, autoWatchKeys, watchCaps, autoPreventDefault, }: HotkeysParams): {
hotkeys: {
(key: string | string[], scope: string, handler: HotkeysHandler): HotkeysCallback;
(key: string | string[], options: HotkeysOptions, handler: HotkeysHandler): HotkeysCallback;
(key: string | string[], handler: HotkeysHandler, options?: HotkeysOptions): HotkeysCallback;
};
watchKeys: () => () => void;
unbindAll: () => void;
unbind: (key?: string, scope?: string) => void;
getScope: () => string;
setScope: (scope: string) => void;
getKeysDown: () => Set<string>;
getKeyboardLayout: () => KeyboardLayout;
setKeyboardLayout: (layout: KeyboardLayout) => void;
setVerbose: (value: boolean) => void;
setEventFilter: (filter: (event: KeyboardEvent) => boolean) => void;
getPressedKeyStrings: () => string[];
trigger: (key: string, scope?: string) => void;
isPressed: (key: string) => boolean;
};
export { createHotkeys };