Listen Events

Ez Hot Keys provides events that you can listen to.

Listen to event

You can listen to events from the HotKeysManager by using the on method.

tsx
import { useHotKeysManagerContext } from "@ez-kits/hot-keys-react";
import { useEffect } from "react";

function MyComponent() {
    const hotKeysManager = useHotKeysManagerContext();

    useEffect(() => {
        return hotKeysManager.on("hot-keys:trigger", (hotKeyInfo, event) => {
            console.log("hot-keys:trigger", hotKeyInfo, event);
        });
    }, [hotKeysManager]);

    return <div>My Component</div>;
}

Supported Events

hot-keys:trigger

Triggered when a hotkey is triggered.

Parameters

  • hotKeyInfo: IHotKeyInfo. The hotkey info.
    • hotKey: string. The hotkey.
    • scopeName: string. Name of the scope where the hot key associated with.
    • ignoreInput: boolean. If true, hot key will not be triggered if user is typing in input or textarea.
    • enabled: boolean. If false, hot key will not be triggered.
    • repeatable: boolean. If true, hot key can be triggered repeatedly.
  • event: KeyboardEvent.

hot-keys:trigger-error

Triggered when a hotkey is found but it cannot be triggered.

Parameters

  • hotKeyInfo: IHotKeyInfo. The hotkey info.
    • hotKey: string. The hotkey.
    • scopeName: string. Name of the scope where the hot key associated with.
    • ignoreInput: boolean. If true, hot key will not be triggered if user is typing in input or textarea.
    • enabled: boolean. If false, hot key will not be triggered.
    • repeatable: boolean. If true, hot key can be triggered repeatedly.
  • event: KeyboardEvent.
  • reason: object. The reason why the hotkey cannot be triggered.
    • disabled: boolean. The hotkey is disabled.
    • ignoreInput: boolean. The hotkey is ignored because the user is typing in input or textarea.
    • repeat: boolean. Repeat is detected but hot key is not repeatable.

hot-keys:register

Triggered when a hotkey is registered.

Parameters

  • hotKey: string. The hot key that is registered.
  • hotKeyInfo: Omit<IHotKeyInfo, "hotKey">. The hot key information.
    • enabled: boolean. If false, hot key will not be triggered.
    • ignoreInput: boolean. If true, hot key will not be triggered if user is typing in input or textarea.
    • repeatable: boolean. If true, hot key can be triggered repeatedly.
    • handler: HotKeyHandler. The handler to call when the hot key is triggered.
  • scope: IHotKeyScopeInstance. The scope that the hot key is registered in.

hot-keys:unregister

Triggered when a hotkey is unregistered.

Parameters

  • hotKey: string. The hotkey.
  • scope: IHotKeyScopeInstance. The scope that the hot key is unregistered from.

scopes:register

Triggered when a scope is registered.

Parameters

  • scope: IHotKeyScopeInstance. The scope that is registered.

scopes:unregister

Triggered when a scope is unregistered.

Parameters

  • scope: IHotKeyScopeInstance. The scope that is unregistered.

scopes:activate

Triggered when a scope is activated.

Parameters

  • scope: IHotKeyScopeInstance. The scope that is activated.

scopes:deactivate

Triggered when a scope is deactivated.

Parameters

  • scope: IHotKeyScopeInstance. The scope that is deactivated.

enabled

Triggered when the hotkeys manager is enabled.

Parameters

No parameters.

disabled

Triggered when the hotkeys manager is disabled.

Parameters

No parameters.