-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbasic.py
More file actions
82 lines (55 loc) · 2.29 KB
/
basic.py
File metadata and controls
82 lines (55 loc) · 2.29 KB
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
import asyncio
import time
from tapsdk import TapInputMode, TapSDK, InputType, AirGestures
def OnDisconnection(identifier):
print("Disconnected. ", identifier)
def OnConnection(identifier):
print("Connected. ", identifier)
def OnMouseModeChange(identifier, mouse_mode):
print(str(identifier) + " changed to mode " + str(mouse_mode))
def OnTapped(identifier, tapcode):
print(str(identifier) + " tapped " + str(tapcode))
def OnGesture(identifier, gesture):
print(str(identifier) + " gesture " + str(AirGestures(gesture)))
def OnMoused(identifier, vx, vy, isMouse):
print(str(identifier) + " mouse movement: %d, %d, %d" % (vx, vy, isMouse))
def OnRawData(identifier, packets):
for m in packets:
print(f"{m['type']}, {time.time()}, {m['payload']}")
async def run(loop):
client = TapSDK(loop=loop)
client.register_disconnection_events(OnDisconnection)
client.register_connection_events(OnConnection)
client.register_air_gesture_events(OnGesture)
client.register_tap_events(OnTapped)
client.register_raw_data_events(OnRawData)
client.register_mouse_events(OnMoused)
client.register_air_gesture_state_events(OnMouseModeChange)
await client.run()
print("Connected: {0}".format(client.client.is_connected))
print("Set Controller Mode for 5 seconds")
await client.set_input_mode(TapInputMode("controller"))
await asyncio.sleep(5)
print("Force Mouse Mode for 5 seconds")
await client.set_input_type(InputType.MOUSE)
await asyncio.sleep(5)
print("Force keyboard Mode for 5 seconds")
await client.set_input_type(InputType.KEYBOARD)
await asyncio.sleep(5)
print("Set auto Mode for 10 seconds")
await client.set_input_type(InputType.AUTO)
await asyncio.sleep(10)
print("Set Text Mode for 10 seconds")
await client.set_input_mode(TapInputMode("text"))
await asyncio.sleep(10)
print("Send Haptics")
await client.send_vibration_sequence([100, 200, 100, 200, 500])
await asyncio.sleep(5)
print("Set Raw Mode for 5 seconds")
await asyncio.sleep(2)
await client.set_input_mode(TapInputMode("raw", sensitivity=[0, 0, 0]))
await asyncio.sleep(5)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.set_debug(True)
loop.run_until_complete(run(loop))