Skip to content

getHotkeyFromKeyboardEvent

Reads the hotkey a key press makes, in the shape Obsidian stores in hotkeys.json.

The Ctrl key reads as Mod everywhere but macOS, and the Command key as Mod on macOS. Letters and digits come from the physical key, so Shift or a keyboard layout does not change them.

Import:

import { getHotkeyFromKeyboardEvent } from '@mnaoumov/obsidian-lib/hotkey';

Signature:

function getHotkeyFromKeyboardEvent(params: GetHotkeyFromKeyboardEventParams): Hotkey | null

Parameters:

Parameter Type Description
params GetHotkeyFromKeyboardEventParams The parameters.

Returns: Hotkey | null — The hotkey, or null when only a modifier key was pressed.


Links to this page: