2525PIXELS = neopixel .NeoPixel (board .NEOPIXEL , 12 , auto_write = False )
2626KEYBOARD = Keyboard (usb_hid .devices )
2727
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 )
3130group .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)
3235
3336DISPLAY .show (group )
3437
@@ -67,7 +70,7 @@ def __init__(self, desc, color, sequence):
6770 self .sequence = sequence
6871 self .in_order = False
6972 for key in sequence :
70- if key .startswith ('-' ):
73+ if key .startswith ('+' ) or key . startswith ( ' -' ):
7174 self .in_order = True
7275 break
7376
@@ -90,7 +93,7 @@ def switch(self):
9093 for i , mac in enumerate (self .macros ):
9194 PIXELS [i ] = mac .color
9295 PIXELS .show ()
93- # DO SCREEN HERE
96+ # Set up screen
9497 text_area .text = self .name
9598
9699
@@ -106,6 +109,10 @@ def switch(self):
106109 while True :
107110 pass
108111
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+
109116LAST_POSITION = None
110117APP_INDEX = 0
111118APPS [APP_INDEX ].switch ()
@@ -117,11 +124,6 @@ def switch(self):
117124 APPS [APP_INDEX ].switch ()
118125 LAST_POSITION = position
119126
120- # PIXELS.fill(0)
121- # PIXELS[position % len(APPS)] = 0xFFFFFF
122- # PIXELS.show()
123- # print(position)
124-
125127 for i , key in enumerate (KEYS ):
126128 action = key .debounce ()
127129 if action is not None :
@@ -131,22 +133,28 @@ def switch(self):
131133 continue # Ignore if key # exceeds macro list length
132134
133135 keys = APPS [APP_INDEX ].macros [i ].sequence
134- if action is False : # Key pressed
136+ if action is False : # Macro key pressed
135137 print ('Press' , i )
136138 if APPS [APP_INDEX ].macros [i ].in_order :
137139 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 ))
142147 else :
143148 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
146151 print ('Release' , i )
152+ # Release all keys in reverse order
147153 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 ))
150158
151159
152160META = ('LEFT_CONTROL' , 'CONTROL' , 'LEFT_SHIFT' , 'SHIFT' , 'LEFT_ALT' , 'ALT' ,
0 commit comments