Skip to content

useHotkeys

Keyboard shortcuts for the chart. Register custom hotkeys globally and enable or disable hotkey handling per chart. Wraps the klinecharts v10 hotkey system.

import { useHotkeys } from "react-klinecharts-ui";
const { registerHotkey, setHotkeysEnabled, supportedHotkeys } = useHotkeys();
// Ctrl/Cmd+L removes every overlay.
registerHotkey({
name: "remove-all-overlays",
keys: ["ctrl+l", "meta+l"],
preventDefault: true,
action: ({ chart }) => chart.removeOverlay(),
});
// Keep hotkeys on, but silence the built-in undo/redo shortcuts.
setHotkeysEnabled(true, ["undo", "redo"]);
PropertyTypeDescription
registerHotkey(template: HotkeyTemplate) => voidRegister a custom hotkey globally (idempotent per name)
getHotkey(name: string) => HotkeyTemplate | nullLook up a registered hotkey by name
supportedHotkeysstring[]Names of every registered hotkey (built-in + custom)
setHotkeysEnabled(enabled: boolean, exclude?: string[]) => voidEnable/disable hotkey handling for the chart; optionally exclude names
getHotkeysConfig() => Hotkey | nullCurrent { enabled, exclude } config for the chart
interface HotkeyTemplate {
name: string;
keys: string | string[];
preventDefault?: boolean;
stopPropagation?: boolean;
check?: (params: HotkeyActionParams) => boolean;
action: (params: HotkeyActionParams) => void;
extendData?: unknown;
}
interface Hotkey {
enabled: boolean;
exclude: string[];
}