-
Notifications
You must be signed in to change notification settings - Fork 71
/
keyboard.py
266 lines (241 loc) · 6.8 KB
/
keyboard.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import os
from time import sleep as sleep
(
mode_choice,
zone_list,
speed_choice,
bright_choice,
direction_choice,
color_choice,
final_command,
) = ([], [], [], [], [], [], [])
choice = 0
def setup():
if not (".keyboard_cache" in [f for f in os.listdir(".") if f.startswith(".")]):
os.system("touch .keyboard_cache")
def prep():
global mode_choice, zone_list, speed_choice, bright_choice, direction_choice, color_choice, final_command
command = "./facer_rgb.py "
if mode_choice:
command += f"-m {mode_choice[0]} "
if speed_choice:
command += f"-s {speed_choice[0]} "
if bright_choice:
command += f"-b {bright_choice[0]} "
if direction_choice:
command += f"-d {direction_choice[0]} "
if color_choice:
command += f"-cR {color_choice[0]} -cB {color_choice[1]} -cG {color_choice[2]} "
if zone_list:
zone = list(map(lambda x: f"-z {x} ", zone_list))
for i in zone:
final_command.append(command + i)
pass
else:
final_command.append(command)
def speed():
global speed_choice, choice
try:
choice = int(
input(
"Enter the Value of Speed [0-9] \n0 -> Static\n1 -> Slowest\n9 -> Fastest\nJust Press Enter to use the Default Value:"
)
)
except ValueError:
os.system("clear")
return None
if choice < 0 or choice > 9:
print("Invalid Choice. Try again")
sleep(1.5)
os.system("clear")
speed()
else:
speed_choice.append(choice)
os.system("clear")
def bright():
global choice, bright_choice
try:
choice = int(
input(
"Enter the Value of Brightness [0-100]\n0 -> Switched Off\n100 -> Brightest\nJust Press Enter to use the Default Value:"
)
)
except ValueError:
os.system("clear")
return None
if choice < 0 or choice > 100:
print("Invalid Choice. Try again")
sleep(1.5)
os.system("clear")
bright()
else:
bright_choice.append(choice)
os.system("clear")
def direction():
global direction_choice, choice
try:
choice = int(
input(
"Enter the Direction of Animation [1/2]"
"\n1 -> Right to Left"
"\n2 -> Left to Right"
"\nJust Press Enter to use the Default Value:"
)
)
except ValueError:
os.system("clear")
return None
if choice not in [1, 2]:
print("Invalid Choice. Try again")
sleep(1.5)
os.system("clear")
direction()
else:
direction_choice.append(choice)
os.system("clear")
def zone():
global zone_list
zones = input(
"Enter the Zone ID(s) you want to select (1-4) seperated by space"
"\nIf you want to select all the zones just press Enter:"
)
if len(zones) == 0:
os.system("clear")
zone_list = [1, 2, 3, 4]
return None
z_list = list(map(lambda x: int(x), zones.split()))
if len(z_list) < 5 and set(z_list).issubset({1, 2, 3, 4}):
zone_list = list(map(lambda x: int(x), zones.split()))
os.system("clear")
else:
print("Invalid Selection, Choose Again")
sleep(1.5)
os.system("clear")
zone()
def color():
global color_choice
raw = input(
"Enter a Valid RGB code with all the channels seperated by space"
"\nExample: 255 255 255"
"\nJust Press Enter to use the Default Color (White):"
)
if len(raw) == 0:
color_choice = [255, 255, 255]
os.system("clear")
return None
inter = raw.split(" ")
values = []
try:
for i in inter:
if i == "":
continue
elif i != "" and (int(i) < 0 or int(i) > 255):
print("RGB values should be between 0 - 255")
sleep(1.5)
os.system("clear")
color()
else:
values.append(int(i))
except ValueError:
print("Invalid Values. Try Again!")
sleep(1.5)
os.system("clear")
color()
if len(values) != 3:
print("There are 3 channels")
sleep(1.5)
os.system("clear")
color()
color_choice = values
os.system("clear")
def rerun():
# This is different from the refresh.sh and should not be considered redundant
# If we are using the Zones Function, then the current script will run multiple commands to match
# all the zones the user has specifies but in this case the refresh will only run the last command.
global final_command
with open(".keyboard_cache", "r") as file:
data = file.read()
final_command.append(data.split(","))
exit()
def run():
global final_command
for i in final_command:
os.system(i)
with open(".keyboard_cache", "w") as file:
file.write(",".join(final_command))
def mode():
global mode_choice, choice
print("Choose the RGB Mode")
print("1. Static")
print("2. Breathing")
print("3. Neon")
print("4. Wave")
print("5. Shifting")
print("6. Zoom")
print("7. Re-Run the Last Command")
print("0. Exit")
try:
choice = int(input("Enter your choice: "))
if choice == 1:
os.system("clear")
mode_choice.append(0)
zone()
color()
elif choice == 2:
os.system("clear")
mode_choice.append(1)
speed()
bright()
color()
elif choice == 3:
os.system("clear")
mode_choice.append(2)
speed()
bright()
elif choice == 4:
os.system("clear")
mode_choice.append(3)
speed()
bright()
direction()
elif choice == 5:
os.system("clear")
mode_choice.append(4)
speed()
bright()
color()
direction()
elif choice == 6:
os.system("clear")
mode_choice.append(5)
speed()
bright()
color()
elif choice == 7:
os.system("clear")
rerun()
elif choice == 0:
os.system("clear")
exit()
else:
print("Invalid Choice")
sleep(2)
os.system("clear")
mode()
except ValueError:
print("Invalid Values. Try Again")
sleep(1.5)
os.system("clear")
mode()
def start():
try:
os.system("clear")
setup()
mode()
prep()
run()
except KeyboardInterrupt:
print("\nExiting the Program")
exit()
if __name__ == "__main__":
start()