import { Reason } from "../constants"; import { Delay } from "../types"; type HotkeyOnceModeOptions = { /** * * if `"once"` - {@link HotkeyOnceModeOptions.action action} will call one time for each hotkey press */ mode: "once"; /** * Method to be executed after the {@link HotkeyOptions.key hotkey} is pressed */ action(this: This): void | Promise; }; type HotkeyRestModesOptions = { /** * * if `"hold"` - {@link HotkeyRestModesOptions.action action} will repeat every {@link HotkeyRestModesOptions.delay delay} milliseconds while hotkey is pressed or {@link HotkeyRestModesOptions.action action} returns `true` * * if `"toggle"` - {@link HotkeyRestModesOptions.action action} starts repeat repeat every {@link HotkeyRestModesOptions.delay delay} milliseconds after hotkey first time pressed and stops after hotkey second time pressed or {@link HotkeyRestModesOptions.action action} returns `false` */ mode: "toggle" | "hold"; /** * Method to check if hotkey is need to be executing * @default () => true */ isEnable?(this: This): boolean | Promise; /** * Method to be executed before the {@link HotkeyRestModesOptions.action action} loop */ before?(this: This): void | Promise; /** * @see {@link HotkeyRestModesOptions.mode mode} */ action(this: This): boolean | Promise; /** * Method to be executed after the {@link HotkeyRestModesOptions.action action} loop * @param reason - reason of {@link HotkeyRestModesOptions.action action} loop ending, can be {@link Reason} (if ended by action - {@link Reason.BY_ACTION}, if ended by keyboard - {@link Reason.BY_KEYBOARD}) or any value from {@link This.stop stop} */ after?(this: This, reason: Reason | R): void | Promise; /** * Delay in milliseconds between {@link HotkeyRestModesOptions.action action} executions * @default 35 */ delay?: Delay; }; export type HotkeyOptions = ([S] extends [never] ? { defaultState?: undefined; } : { defaultState: S; }) & (HotkeyOnceModeOptions | HotkeyRestModesOptions); declare class _Hotkey { /** * Any state that also can be used via `this` in {@link HotkeyRestModesOptions.isEnable isEnable}, {@link HotkeyRestModesOptions.before before}, {@link HotkeyRestModesOptions.action action}, {@link HotkeyRestModesOptions.after after} methods */ state: S; isRunning: boolean; /** * Stops the loop of {@link HotkeyRestModesOptions.action action} executing * @param [reason=Reason.BY_STOP] - reason to {@link HotkeyRestModesOptions.after after}, if not provided defaults to {@link Reason.BY_STOP} */ stop(reason?: Reason.BY_STOP | R): Promise | undefined; protected _getButtonState(): boolean; } export type Hotkey = Omit<_Hotkey, never>; declare function handleAction(this: _Hotkey, options: HotkeyOptions<_Hotkey, S, R>): () => void; export default handleAction;