-
Notifications
You must be signed in to change notification settings - Fork 783
/
keys.py
203 lines (170 loc) · 4.9 KB
/
keys.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
from talon import Context, Module, actions, app
mod = Module()
mod.list("letter", desc="The spoken phonetic alphabet")
mod.list("symbol_key", desc="All symbols from the keyboard")
mod.list("arrow_key", desc="All arrow keys")
mod.list("number_key", desc="All number keys")
mod.list("modifier_key", desc="All modifier keys")
mod.list("function_key", desc="All function keys")
mod.list("special_key", desc="All special keys")
mod.list("keypad_key", desc="All keypad keys")
mod.list("punctuation", desc="words for inserting punctuation into text")
@mod.capture(rule="{self.modifier_key}+")
def modifiers(m) -> str:
"One or more modifier keys"
return "-".join(m.modifier_key_list)
@mod.capture(rule="{self.arrow_key}")
def arrow_key(m) -> str:
"One directional arrow key"
return m.arrow_key
@mod.capture(rule="<self.arrow_key>+")
def arrow_keys(m) -> str:
"One or more arrow keys separated by a space"
return str(m)
@mod.capture(rule="{self.number_key}")
def number_key(m) -> str:
"One number key"
return m.number_key
@mod.capture(rule="{self.keypad_key}")
def keypad_key(m) -> str:
"One keypad key"
return m.keypad_key
@mod.capture(rule="{self.letter}")
def letter(m) -> str:
"One letter key"
return m.letter
@mod.capture(rule="{self.special_key}")
def special_key(m) -> str:
"One special key"
return m.special_key
@mod.capture(rule="{self.symbol_key}")
def symbol_key(m) -> str:
"One symbol key"
return m.symbol_key
@mod.capture(rule="{self.function_key}")
def function_key(m) -> str:
"One function key"
return m.function_key
@mod.capture(rule="( <self.letter> | <self.number_key> | <self.symbol_key> )")
def any_alphanumeric_key(m) -> str:
"any alphanumeric key"
return str(m)
@mod.capture(
rule="( <self.letter> | <self.number_key> | <self.symbol_key> "
"| <self.arrow_key> | <self.function_key> | <self.special_key> | <self.keypad_key>)"
)
def unmodified_key(m) -> str:
"A single key with no modifiers"
return str(m)
@mod.capture(rule="{self.modifier_key}* <self.unmodified_key>")
def key(m) -> str:
"A single key with optional modifiers"
try:
mods = m.modifier_key_list
except AttributeError:
mods = []
return "-".join(mods + [m.unmodified_key])
@mod.capture(rule="<self.key>+")
def keys(m) -> str:
"A sequence of one or more keys with optional modifiers"
return " ".join(m.key_list)
@mod.capture(rule="{self.letter}+")
def letters(m) -> str:
"Multiple letter keys"
return "".join(m.letter_list)
ctx = Context()
# `punctuation_words` is for words you want available BOTH in dictation and as key names in command mode.
# `symbol_key_words` is for key names that should be available in command mode, but NOT during dictation.
punctuation_words = {
# TODO: I'm not sure why we need these, I think it has something to do with
# Dragon. Possibly it has been fixed by later improvements to talon? -rntz
"`": "`",
",": ",", # <== these things
"back tick": "`",
"comma": ",",
# Workaround for issue with conformer b-series; see #946
"coma": ",",
"period": ".",
"full stop": ".",
"semicolon": ";",
"colon": ":",
"forward slash": "/",
"question mark": "?",
"exclamation mark": "!",
"exclamation point": "!",
"asterisk": "*",
"hash sign": "#",
"number sign": "#",
"percent sign": "%",
"at sign": "@",
"and sign": "&",
"ampersand": "&",
# Currencies
"dollar sign": "$",
"pound sign": "£",
"hyphen": "-",
"L paren": "(",
"left paren": "(",
"R paren": ")",
"right paren": ")",
}
symbol_key_words = {
"dot": ".",
"point": ".",
"quote": "'",
"question": "?",
"apostrophe": "'",
"L square": "[",
"left square": "[",
"brack": "[",
"bracket": "[",
"left bracket": "[",
"square": "[",
"R square": "]",
"right square": "]",
"r brack": "]",
"r bracket": "]",
"right bracket": "]",
"slash": "/",
"backslash": "\\",
"minus": "-",
"dash": "-",
"equals": "=",
"plus": "+",
"grave": "`",
"tilde": "~",
"bang": "!",
"down score": "_",
"underscore": "_",
"paren": "(",
"brace": "{",
"left brace": "{",
"curly bracket": "{",
"left curly bracket": "{",
"r brace": "}",
"right brace": "}",
"r curly bracket": "}",
"right curly bracket": "}",
"angle": "<",
"left angle": "<",
"less than": "<",
"rangle": ">",
"R angle": ">",
"right angle": ">",
"greater than": ">",
"star": "*",
"hash": "#",
"percent": "%",
"caret": "^",
"amper": "&",
"pipe": "|",
"dub quote": '"',
"double quote": '"',
# Currencies
"dollar": "$",
"pound": "£",
}
# make punctuation words also included in {user.symbol_keys}
symbol_key_words.update(punctuation_words)
ctx.lists["self.punctuation"] = punctuation_words
ctx.lists["self.symbol_key"] = symbol_key_words