-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
100 lines (70 loc) · 2.43 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import subprocess
import hid
MY_DEVICE = (0x0810, 0x0001)
def trigger_adb_event(id):
subprocess.run(f"adb shell input keyevent {id}", shell=True)
def trigger_adb_roll(x, y):
subprocess.run(f"adb shell input joystick roll {x} {y}", shell=True)
def main():
for device in hid.enumerate():
print(
f"0x{device['vendor_id']:04x}:0x{device['product_id']:04x} {device['product_string']}"
)
gamepad = hid.device()
gamepad.open(*MY_DEVICE)
gamepad.set_nonblocking(True)
while True:
report = gamepad.read(64)
if report:
if report[5] == 0:
print("Up pressed")
trigger_adb_event(19)
if report[5] == 4:
print("Down pressed")
trigger_adb_event(20)
if report[5] == 6:
print("left pressed")
trigger_adb_event(21)
if report[5] == 2:
print("right pressed")
trigger_adb_event(22)
if report[3] == 127 and report[4] == 127:
trigger_adb_roll(0, 0)
if report[5] == 31:
print("y pressed")
trigger_adb_event(100)
if report[5] == 47:
print("b pressed")
trigger_adb_event(97)
if report[5] == 79:
print("a pressed")
trigger_adb_event(96)
if report[5] == 143:
print("x pressed")
trigger_adb_event(99)
if report[6] == 2:
print("l1 pressed")
trigger_adb_event(103)
if report[6] == 4:
print("l2 pressed")
trigger_adb_event(104)
if report[6] == 1:
print("r1 pressed")
trigger_adb_event(102)
if report[6] == 8:
print("r2 pressed")
trigger_adb_event(105)
if report[6] == 32:
print("start pressed")
trigger_adb_event(108)
if report[6] == 16:
print("select pressed")
trigger_adb_event(109)
if report[6] == 64:
print("thumbl pressed")
if report[6] == 128:
print("thumbr pressed")
trigger_adb_roll((report[3] - 127) / 127, (report[4] - 127) / 127)
print(report)
if __name__ == "__main__":
main()