-
Notifications
You must be signed in to change notification settings - Fork 25
/
Air_Mouse.py
53 lines (47 loc) · 1.27 KB
/
Air_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
from pynput.mouse import Button,Controller
import socket
import bs4
import time
import math
ip = '192.168.1.17'
port = 5555
sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.bind((ip,port))
oldz = 9
mouse = Controller()
def sensor_data():
sauce = bs4.BeautifulSoup(data,'lxml')
x = sauce.find('accelerometer1')
X = int(float(x.text))
y = sauce.find('accelerometer2')
Y = int(float(y.text))
z = sauce.find('accelerometer3')
Z = int(float(z.text))
print('X: ' + str(X))
print('Y: ' + str(Y))
print('Z: ' + str(Z))
single_click = sauce.find('lightintensity')
mouse.move(-X*6,Y*6)
#left click
if int(float(single_click.text)) <= 10:
mouse.click(Button.left)
mouse.release(Button.left)
print("Left Click")
#right click
if oldz > Z:
if oldz - Z > 2:
mouse.click(Button.right)
mouse.release(Button.right)
print("Right Click")
else:
saveold()
def saveold():
sauce = bs4.BeautifulSoup(data,'lxml')
z = sauce.find('accelerometer3')
Z = int(float(z.text))
oldz = Z
while True:
rawdata = sock.recvfrom(port)
data = str(rawdata)
sensor_data()
time.sleep(0)