forked from AceCentre/RelayKeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli_keymap.py
33 lines (27 loc) · 866 Bytes
/
cli_keymap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from pathlib import Path
import json
nonchars_key_map = None
def load_keymap_file(config):
global nonchars_key_map
keymap_file = Path(__file__).resolve().parent / "cli_keymaps" / config.get("keymap_file", "us_keymap.json")
if keymap_file.exists() and keymap_file.is_file():
with open(keymap_file, "r", encoding="utf-8") as f:
try:
nonchars_key_map = json.loads(f.read())
except Exception as e:
print("Invalid keymap json file:", e)
return
else:
print("Invalid path to keymap file:", keymap_file)
return False
return True
def char_to_keyevent_params (char):
global nonchars_key_map
ret = nonchars_key_map.get(char, None)
if ret is not None:
return ret
if (char.isdigit()):
return (char,[])
if (char.upper() == char):
return (char.upper(),["LSHIFT"])
return (char.upper(),[])