-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetmouse.py
56 lines (41 loc) · 1.26 KB
/
getmouse.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
from pynput import mouse
import time
class GetMouse():
def __init__(self):
self.pos = []
self.pts=[]
# ...or, in a non-blocking fashion:
self.listener = mouse.Listener(
on_move=self.on_move,
on_click=self.on_click,
on_scroll=self.on_scroll)
self.listener.start()
def stop(self):
self.listener.stop()
def on_move(self,x, y):
#print('Pointer moved to {0}'.format((x, y)))
self.pos=[x,y]
def on_click(self,x, y, button, pressed):
print('{0} at {1}'.format(
'Pressed' if pressed else 'Released',
(x, y)))
if pressed:
self.pts.append([x,y])
# Stop listener
#return False
def on_scroll(self,x, y, dx, dy):
pass
#print('Scrolled {0} at {1}'.format('down' if dy < 0 else 'up',(x, y)))
def getpts(self):
#get clicked points
return self.pts
def clear(self):
mobj.pts=[]
if __name__ == '__main__':
mobj = GetMouse()
while 1:
time.sleep(.5)
pts = mobj.getpts()
if pts:
print('mobj: ',pts[-1])
print('current pos: ',mobj.pos)