Validate hotkeys and support Super alias

This commit is contained in:
Thales Maciel 2026-02-25 11:51:39 -03:00
parent 2cbc1a98b9
commit 3bc473262d
6 changed files with 138 additions and 34 deletions

30
src/hotkey.py Normal file
View file

@ -0,0 +1,30 @@
from __future__ import annotations
HOTKEY_MODIFIERS = {
"shift",
"ctrl",
"control",
"alt",
"mod1",
"super",
"mod4",
"cmd",
"command",
}
def split_hotkey(hotkey: str) -> tuple[list[str], str]:
parts = [p.strip() for p in hotkey.split("+") if p.strip()]
modifiers: list[str] = []
key_part = ""
for part in parts:
low = part.lower()
if low in HOTKEY_MODIFIERS:
modifiers.append(low)
continue
if key_part:
raise ValueError("must include exactly one non-modifier key")
key_part = part
if not key_part:
raise ValueError("missing key")
return modifiers, key_part