99import usb_hid
1010from adafruit_hid .keyboard import Keyboard
1111from adafruit_hid .keycode import Keycode
12+ from adafruit_hid .mouse import Mouse
1213
14+ mouse = Mouse (usb_hid .devices )
1315# neopixel colors
1416RED = (255 , 0 , 0 )
1517ORANGE = (255 , 127 , 0 )
1921BLUE = (0 , 0 , 255 )
2022PURPLE = (127 , 0 , 255 )
2123PINK = (255 , 0 , 255 )
22- OFF = (0 , 0 , 0 )
24+ OFF = (50 , 50 , 50 )
2325# axis states selected with keys 9-11
2426axis_states = [0 , "x" , "y" , "z" ]
2527state = axis_states [0 ]
2628# keymap for key matrix
2729keymap = {
28- (0 ): (axis_states [0 ], [ Keycode .HOME ], RED ), # HOME X/Y
29- (1 ): (axis_states [0 ], [ Keycode .END ], ORANGE ), # HOME Z
30- (2 ): (axis_states [0 ], (Keycode .HOME , Keycode .END ), YELLOW ), # HOME ALL
30+ (0 ): (axis_states [0 ], ( Keycode .COMMAND , Keycode . COMMA ), BLUE ), # SETTINGS
31+ (1 ): (axis_states [0 ], ( Keycode .COMMAND , Keycode . P ), ORANGE ), # SLICE MODEL
32+ (2 ): (axis_states [0 ], (Keycode .COMMAND , Keycode .D ), RED ), # CLEAR BED
3133
32- (3 ): (axis_states [0 ], ( Keycode .SHIFT , Keycode . A ), GREEN ), # SHORTCUT A
33- (4 ): (axis_states [0 ], ( Keycode .SHIFT , Keycode . B ), AQUA ), # SHORTCUT B
34- (5 ): (axis_states [0 ], ( Keycode .SHIFT , Keycode . C ), BLUE ), # SHORTCUT C
34+ (3 ): (axis_states [0 ], [ Keycode .T ], GREEN ), # MOVE
35+ (4 ): (axis_states [0 ], [ Keycode .S ], AQUA ), # SCALE
36+ (5 ): (axis_states [0 ], [ Keycode .R ], BLUE ), # ROTATE
3537
36- (6 ): (axis_states [0 ], [Keycode .TWO ], AQUA ), # SET STEPS 1MM
37- (7 ): (axis_states [0 ], [Keycode .THREE ], PURPLE ), # SET STEPS 10MM
38- (8 ): (axis_states [0 ], [Keycode .FOUR ], PINK ), # SET STEPS 100MM
38+ (6 ): (axis_states [0 ], [Keycode .M ], AQUA ), # MIRROR
39+ (7 ): (axis_states [0 ], [Keycode .E ], PURPLE ), # SUPPORT BLOCKERS
40+ (8 ): (axis_states [0 ], [Keycode .I ], PINK ), # TABS
3941
4042 (9 ): (axis_states [1 ], None , RED ), # SET X-AXIS STATE
4143 (10 ): (axis_states [2 ], None , GREEN ), # SET Y-AXIS STATE
4547encoder_map = {
4648 ("x" ): ([Keycode .RIGHT_ARROW ], [Keycode .LEFT_ARROW ]),
4749 ("y" ): ([Keycode .UP_ARROW ], [Keycode .DOWN_ARROW ]),
48- ("z" ): ([Keycode .W ], [Keycode .S ]),
50+ # ("z"): ([Keycode.W], [Keycode.S]),
4951}
5052# make a keyboard
5153kbd = Keyboard (usb_hid .devices )
@@ -88,7 +90,7 @@ def key_to_pixel_map(key_number):
8890 kbd .press (* encoder_map [state ][0 ])
8991 # ..and state is z:
9092 if state is axis_states [3 ]:
91- kbd . press ( * encoder_map [ state ][ 0 ] )
93+ mouse . move ( wheel = - 1 )
9294 # ..and it decreases..
9395 if position < last_position :
9496 # ..and state is x:
@@ -99,7 +101,7 @@ def key_to_pixel_map(key_number):
99101 kbd .press (* encoder_map [state ][1 ])
100102 # ..and state is z:
101103 if state is axis_states [3 ]:
102- kbd . press ( * encoder_map [ state ][ 1 ] )
104+ mouse . move ( wheel = 1 )
103105 # print(position)
104106 # release all keys
105107 kbd .release_all ()
0 commit comments