-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
50 lines (39 loc) · 1.05 KB
/
main.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
def main():
port = "COM6"
rate = 9600
arduino = serial.Serial(port, rate, timeout=0.1)
input = Input()
input.new_action(
"mouse",
input.bindings.vector2("joy_x", "joy_y"),
[
input.processors.map(0, 1023, -1, 1),
input.processors.deadzone(0.05)
]
)
input.new_action(
"click",
input.bindings.value("joy_b")
)
controller = Controller()
#input.on_change("mouse", lambda value: print("new Δmouse", value))
input.on_change("click", lambda value: controller.click(Button.left) if value else None)
while True:
# Removing the last two characters to remove new line characters
data = arduino.readline()[:-2]
if data:
input.update_input(json.loads(data.decode("utf-8")))
else:
continue
mouse = input.get("mouse")
print(mouse)
if mouse != [0, 0]:
controller.move(*[component * 60 for component in mouse])
if __name__ == "__main__":
import serial
from pynput.mouse import Button, Controller
from input import Input
import os
import json
import time
main()