interface ICommandHandler {
    pressedKeys: string[];
    canExecuteCommand<T>(name: string, throwOnNonexisting?: boolean, ...args: Parameters<T["execute"]>): boolean;
    executeCommand<T>(name: string, throwOnNonexisting?: false, ...args: Parameters<T["execute"]>): void | ReturnType<T["execute"]>;
    executeCommand<T>(name: string, throwOnNonexisting: true, ...args: Parameters<T["execute"]>): ReturnType<T["execute"]>;
    handleKeyDown(ev: KeyboardEvent): void;
    handleKeyUp(ev: KeyboardEvent): void;
    hasCommand(name: string): boolean;
    registerCommand<T>(name: string, command: T): void;
    registerHotkey(keys: string[], commandName: string, options?: HotkeyRegistrationOptions): 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

    • OptionalthrowOnNonexisting: 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

    • OptionalthrowOnNonexisting: 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.

    • Optionaloptions: HotkeyRegistrationOptions

      Options for the hotkey registration.

    Returns void