interface ICommandHandler {
    pressedKeys: string[];
    canExecuteCommand<T>(name, throwOnNonexisting?, ...args): boolean;
    executeCommand<T>(name, throwOnNonexisting?, ...args): void | ReturnType<T["execute"]>;
    executeCommand<T>(name, throwOnNonexisting, ...args): ReturnType<T["execute"]>;
    handleKeyDown(ev): void;
    handleKeyUp(ev): void;
    hasCommand(name): boolean;
    registerCommand<T>(name, command): void;
    registerHotkey(keys, commandName, options?): void;
}

Properties

pressedKeys: string[]

Currently pressed keys

Methods

  • Checks whether the command can be executed at the present time.

    Type Parameters

    • T extends AbstractCommand

    Parameters

    • name: string

      Name of the command

    • Optional throwOnNonexisting: boolean

      Whether to throw an error if the command with the specified name does not exist. If set to false and the command doesn't exist, the method will just return false.

    • Rest ...args: Parameters<T["execute"]>

    Returns boolean

  • Executes the command with the given name

    Type Parameters

    • T extends AbstractCommand

    Parameters

    • name: string

      Name of the command

    • Optional throwOnNonexisting: false

      Whether to throw an error if the command with the specified name does not exist. If set to false and the command doesn't exist, the method will just return undefined.

    • Rest ...args: Parameters<T["execute"]>

    Returns void | ReturnType<T["execute"]>

  • Executes the command with the given name

    Type Parameters

    • T extends AbstractCommand

    Parameters

    • name: string

      Name of the command

    • throwOnNonexisting: true

      Whether to throw an error if the command with the specified name does not exist. If set to false and the command doesn't exist, the method will just return undefined.

    • Rest ...args: Parameters<T["execute"]>

    Returns ReturnType<T["execute"]>

  • Register a new command

    Type Parameters

    • T extends AbstractCommand

    Parameters

    • name: string

      Name of the command

    • command: T

      Command definition

    Returns void

  • Register a new hotkey combination for the command.

    Parameters

    • keys: string[]

      Combination of keys. When all keys in the given array are pressed at the same time, the command will be executed.

    • commandName: string

      Name of the command that should be executed when the keys are pressed.

    • Optional options: HotkeyRegistrationOptions

      Options for the hotkey registration.

    Returns void