-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcode.py
executable file
·55 lines (47 loc) · 1.51 KB
/
code.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
import board
import time
import usb_hid
from digitalio import DigitalInOut, Direction, Pull
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
switch = DigitalInOut(board.GP4)
switch.direction = Direction.INPUT
switch.pull = Pull.UP
bt1 = DigitalInOut(board.GP18)
bt1.direction = Direction.INPUT
bt1.pull = Pull.UP
bt2 = DigitalInOut(board.GP20)
bt2.direction = Direction.INPUT
bt2.pull = Pull.UP
led = DigitalInOut(board.GP10)
led.direction = Direction.OUTPUT
keyboard=Keyboard(usb_hid.devices)
bt1Released = True
bt2Released = True
while True:
if not bt1.value and bt1Released:
bt1Released = False
if switch.value:
#MacOs
print("Button 1, Switch position 1")
led.value = not led.value
keyboard.send(Keycode.GUI, Keycode.SHIFT, Keycode.M)
else:
#Windows
print("Button 1, Switch position 2")
led.value = not led.value
keyboard.send(Keycode.CONTROL, Keycode.SHIFT, Keycode.M)
if not bt2.value and bt2Released:
bt2Released = False
if switch.value:
#MacOs
print("Button 2, Switch position 1")
keyboard.send(Keycode.GUI, Keycode.SHIFT, Keycode.B)
else:
#Windows
print("Button 2, Switch position 2")
keyboard.send(Keycode.CONTROL, Keycode.SHIFT, Keycode.B)
if bt1.value and not bt1Released:
bt1Released = true
if bt2.value and not bt2Released:
bt2Released = true