-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
125 lines (113 loc) · 2.4 KB
/
main.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
from vocoder.app import App
from vocoder.grammar import Grammar
from vocoder.lexicons import en_frequent, python_keywords
from pynput.keyboard import Controller, Key
keyboard = Controller()
def execute_chord(mods, term):
with keyboard.pressed(*mods):
keyboard.press(term)
keyboard.release(term)
g = Grammar()
g(f"""
!start = < !sleep | !command | !exit >
!sleep = ~(vocoder sleep) <* :en > ~(vocoder wake)
!exit = ~(vocoder exit) => %{g(lambda env: env.app.exit())}
!command = !chord | !phrase [rest]
!phrase ~= phrase < :python+:en-:python_homophones > -> %type
!chord ~= <*:modifier> @mods :terminal @term => %{g(execute_chord)}
%type = %{g(lambda words: keyboard.type(" ".join(words)))}
:reserved = vocoder+rest
:en = :{g(en_frequent(30_000))}-:reserved
:python = :{g(python_keywords)}
:python_homophones = deaf+death
:modifier = :{g({
"soup": Key.cmd,
"troll": Key.ctrl,
"shift": Key.shift,
"alt": Key.alt,
})}
:terminal = :{g({
"tick": "`",
"tilde": "~",
"bang": "!",
"lat": "@",
"hash": "#",
"doll": "$",
"mod": "%",
"try": "^",
"amp": "&",
"star": "*",
"lep": "(",
"rep": ")",
"mine": "-",
"score": "_",
"lane": "=",
"plus": "+",
"lace": "[",
"race": "]",
"lack": "{",
"rack": "}",
"pipe": "|",
"wink": ";",
"coal": ":",
"chick": "'",
"dub": '"',
"lang": "<",
"rang": ">",
"com": ",",
"pier": ".",
"slash": "/",
"quest": "?",
"ack": "a",
"bat": "b",
"cap": "c",
"drum": "d",
"each": "e",
"fine": "f",
"gust": "g",
"harp": "h",
"sit": "i",
"jury": "j",
"crunch": "k",
"look": "l",
"made": "m",
"near": "n",
"odd": "o",
"pit": "p",
"quench": "q",
"red": "r",
"sun": "s",
"trap": "t",
"urge": "u",
"vest": "v",
"whale": "w",
"plex": "x",
"yank": "y",
"zip": "z",
"zero": "0",
"one": "1",
"two": "2",
"three": "3",
"four": "4",
"five": "5",
"six": "6",
"seven": "7",
"eight": "8",
"nine": "9",
"left": Key.left,
"right": Key.right,
"up": Key.up,
"down": Key.down,
"tab": Key.tab,
"eggs": Key.esc,
"slap": Key.enter,
"spooce": Key.space,
"home": Key.home,
"pageup": Key.page_up,
"pagedown": Key.page_down,
"end": Key.end,
"junk": Key.backspace,
"del": Key.delete,
})}
""")
App(g).run()