-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-websocket.py
More file actions
executable file
·42 lines (35 loc) · 923 Bytes
/
test-websocket.py
File metadata and controls
executable file
·42 lines (35 loc) · 923 Bytes
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
#!/usr/bin/env python
"""Send mouse input to the floating-pointer WebSocket interface.
"""
import asyncio
import logging
import math
import sys
import time
import websockets
log = logging.getLogger(__name__)
def main():
while True:
try:
asyncio.run(test())
except Exception as e:
print(str(e))
time.sleep(1)
async def test():
uri = "ws://localhost:7780/ws"
async with websockets.connect(uri) as websocket:
i, x, y = 0, 0, 0
while True:
xx = int(math.cos(i) * 100)
yy = int(math.sin(i) * 100)
msg = f'touch {x - xx} {y - yy}'
x = xx
y = yy
await websocket.send(f'{msg}\n'.encode('ascii'))
print(f'Sent: {msg}')
time.sleep(.01)
i += .1
if i >= 360:
i -= 360
if __name__ == '__main__':
sys.exit(main())