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"]);Try it
Section titled “Try it”| Property | Type | Description |
|---|---|---|
registerHotkey | (template: HotkeyTemplate) => void | Register a custom hotkey globally (idempotent per name) |
getHotkey | (name: string) => HotkeyTemplate | null | Look up a registered hotkey by name |
supportedHotkeys | string[] | Names of every registered hotkey (built-in + custom) |
setHotkeysEnabled | (enabled: boolean, exclude?: string[]) => void | Enable/disable hotkey handling for the chart; optionally exclude names |
getHotkeysConfig | () => Hotkey | null | Current { 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[];}