25
25
PIXELS = neopixel .NeoPixel (board .NEOPIXEL , 12 , auto_write = False )
26
26
KEYBOARD = Keyboard (usb_hid .devices )
27
27
28
- group = displayio .Group (max_size = 10 )
29
- text1 = "0123\n 4567\n 89AB\n CDEF\n 1234\n 5678\n 9AB"
30
- text_area = label .Label (terminalio .FONT , text = text1 , color = 0xFFFFFF , x = 8 , y = 8 )
28
+ group = displayio .Group (max_size = 13 )
29
+ text_area = label .Label (terminalio .FONT , text = 'M' , color = 0xFFFFFF , x = DISPLAY .width // 2 , y = 0 , anchor_point = (0.5 , 0.0 ), max_glyphs = 30 )
31
30
group .append (text_area )
31
+ # Use baseline alignment for these!
32
+ #labels = []
33
+ #for i in range(13):
34
+ # labels.append = label.Label(terminalio.FONT, text='M', color=0xFFFFFF, x=0, y=0, max_glyphs=15)
32
35
33
36
DISPLAY .show (group )
34
37
@@ -67,7 +70,7 @@ def __init__(self, desc, color, sequence):
67
70
self .sequence = sequence
68
71
self .in_order = False
69
72
for key in sequence :
70
- if key .startswith ('-' ):
73
+ if key .startswith ('+' ) or key . startswith ( ' -' ):
71
74
self .in_order = True
72
75
break
73
76
@@ -90,7 +93,7 @@ def switch(self):
90
93
for i , mac in enumerate (self .macros ):
91
94
PIXELS [i ] = mac .color
92
95
PIXELS .show ()
93
- # DO SCREEN HERE
96
+ # Set up screen
94
97
text_area .text = self .name
95
98
96
99
@@ -106,6 +109,10 @@ def switch(self):
106
109
while True :
107
110
pass
108
111
112
+ # Convert key code name (e.g. "COMMAND") to a numeric value for press/release
113
+ def code (name ):
114
+ return eval ('Keycode.' + name .upper ())
115
+
109
116
LAST_POSITION = None
110
117
APP_INDEX = 0
111
118
APPS [APP_INDEX ].switch ()
@@ -117,11 +124,6 @@ def switch(self):
117
124
APPS [APP_INDEX ].switch ()
118
125
LAST_POSITION = position
119
126
120
- # PIXELS.fill(0)
121
- # PIXELS[position % len(APPS)] = 0xFFFFFF
122
- # PIXELS.show()
123
- # print(position)
124
-
125
127
for i , key in enumerate (KEYS ):
126
128
action = key .debounce ()
127
129
if action is not None :
@@ -131,22 +133,28 @@ def switch(self):
131
133
continue # Ignore if key # exceeds macro list length
132
134
133
135
keys = APPS [APP_INDEX ].macros [i ].sequence
134
- if action is False : # Key pressed
136
+ if action is False : # Macro key pressed
135
137
print ('Press' , i )
136
138
if APPS [APP_INDEX ].macros [i ].in_order :
137
139
for x in APPS [APP_INDEX ].macros [i ].sequence :
138
- if x .startswith ('-' ):
139
- KEYBOARD .release (eval ('Keycode.' + x [1 :]))
140
- else :
141
- KEYBOARD .press (eval ('Keycode.' + x ))
140
+ if x .startswith ('+' ): # Press and hold key
141
+ KEYBOARD .press (code (x [1 :]))
142
+ elif x .startswith ('-' ): # Release key
143
+ KEYBOARD .release (code (x [1 :]))
144
+ else : # Press and release key
145
+ KEYBOARD .press (code (x ))
146
+ KEYBOARD .release (code (x ))
142
147
else :
143
148
for x in APPS [APP_INDEX ].macros [i ].sequence :
144
- KEYBOARD .press (eval ( 'Keycode.' + x ))
145
- elif action is True : # Key released
149
+ KEYBOARD .press (code ( x ))
150
+ elif action is True : # Macro key released
146
151
print ('Release' , i )
152
+ # Release all keys in reverse order
147
153
for x in reversed (APPS [APP_INDEX ].macros [i ].sequence ):
148
- if not x .startswith ('-' ):
149
- KEYBOARD .release (eval ('Keycode.' + x ))
154
+ if x .startswith ('+' ) or x .startswith ('-' ):
155
+ KEYBOARD .release (code (x [1 :]))
156
+ else :
157
+ KEYBOARD .release (code (x ))
150
158
151
159
152
160
META = ('LEFT_CONTROL' , 'CONTROL' , 'LEFT_SHIFT' , 'SHIFT' , 'LEFT_ALT' , 'ALT' ,
0 commit comments