-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqmk-chorded.py
87 lines (74 loc) · 2.55 KB
/
qmk-chorded.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import csv
import utils
# Limit how many rows to process since microcontrollers such as pro micro have quite limited memory
# You'll need to lower this if you get memory errors when compiling
limit = 0
# Needs to match what you have defined in your keymap. If you have other mod tap with alphas you need to map each to a letter. If you aren't using mod tap you can remove the alpha mappings here and restore `KC_SCLN` for semicolon.
key_map = {
"C": "KC_SFT_C",
"I": "KC_ALT_I",
"E": "KC_GUI_E",
"A": "KC_CTL_A",
"H": "KC_CTL_H",
"T": "KC_GUI_T",
"S": "KC_ALT_S",
"N": "KC_SFT_N",
"J": "KC_CAG_J",
"M": "KC_CAG_M",
";": "KC_SCLN",
",": "KC_COMMA",
".": "KC_DOT",
"'": "KC_QUOT",
"-": "KC_MINUS",
"←": "KC_BSPC",
}
seen = {}
output = ""
line_no = 0
trigger_keys = ["KC_COMBO"]
shifted_keys = ["KC_COMBO_SFT"]
alt_keys = [["KC_COMBO_ALT1"], ["KC_COMBO_ALT2"], ["KC_COMBO_ALT1", "KC_COMBO_ALT2"]]
def translate_keys(abbr):
result = trigger_keys.copy()
for k in abbr:
k = k.upper()
if k in key_map:
result.append(key_map[k])
else:
result.append(f"KC_{k}")
return result
print("Processing abbr.tsv")
with open("abbr.tsv") as file:
file = csv.reader(file, delimiter="\t")
for p in [";", ",", "."]:
name = f"c_{key_map[p]}"
keys = translate_keys(p)
output += f'SUBS({name}, SS_TAP(X_BSPC)"{p} ", {", ".join(keys)})\n'
for line in file:
line_no += 1
if limit != 0 and line_no > limit:
print(f"Stopping at line {limit} due to limit setting")
break
if line[1]:
abbr = line.pop(1)
if abbr in seen:
raise Exception(
f'Error line {line_no}: already used trigger "{abbr}" for word "{seen[abbr]}"'
)
combinations = utils.find_all_combinations(abbr)
for a in combinations:
seen[a] = line[0]
keys = translate_keys(abbr)
for i, word in enumerate(line):
if not word:
continue
alt = []
if i != 0:
alt = alt_keys[i - 1]
name = f"c_{abbr}{i}".replace("'", "_").replace("-", "_")
output += f'SUBS({name}, "{word} ", {", ".join(keys + alt)})\n'
output += f'SUBS({name}s, "{word.capitalize()} ", {", ".join(keys + alt + shifted_keys)})\n'
print("writing abbr.def")
with open("abbr.def", "w") as file:
file.write(output)
print("done")