forked from chetbox/android-mouse-cursor
-
Notifications
You must be signed in to change notification settings - Fork 5
/
mouse.py
55 lines (46 loc) · 1.38 KB
/
mouse.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
import socket
def getch(): # define non-Windows version
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
# get your phones IP by visiting https://www.whatismyip.com/
# then specify your IPv6 here like so
UDP_IP = "2a01:30:2a04:3c1:c83c:2315:9d2b:9a40" # IPv6
UDP_PORT = 9999
print "UDP target IP:", UDP_IP
print "UDP target port:", UDP_PORT
print ""
print "W, A, S, D - Move mouse"
print "Space - Click"
print "Q - Quit"
# IPv6
sock = socket.socket(socket.AF_INET6, # Internet
socket.SOCK_DGRAM) # UDP
# IPv4
# sock = socket.socket(socket.AF_INET, # Internet
# socket.SOCK_DGRAM) # UDP
while True:
key = ord(getch())
if key == 119: # W
# print 'up'
sock.sendto('0', (UDP_IP, UDP_PORT))
elif key == 97: # A
# print 'left'
sock.sendto('2', (UDP_IP, UDP_PORT))
elif key == 115: # S
# print 'down'
sock.sendto('1', (UDP_IP, UDP_PORT))
elif key == 100: # D
# print 'right'
sock.sendto('3', (UDP_IP, UDP_PORT))
elif key == 113: # Q
break
elif key == 32: # Space
# print 'click'
sock.sendto('4', (UDP_IP, UDP_PORT))