-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinux_mouse_controller.py
More file actions
73 lines (53 loc) · 1.53 KB
/
Linux_mouse_controller.py
File metadata and controls
73 lines (53 loc) · 1.53 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
#-*- coding: utf-8 -*-
import autopy
class Mouse():
"""a class containing attributes and methods needed to controlling mouse cursor"""
def __init__(self, x=100, y=100):
self.maxX, self.maxY=autopy.screen.get_size()
if (x in range(0, self.maxX)) and (y in range(0, self.maxY)):
self.moveTo(x, y)
else:
self.moveTo(0, 0)
def moveTo(self, x, y):
"""moves mouse cursor to (x,y) position"""
if x < 0:
self.x = 0
elif x > self.maxX:
self.x = self.maxX
else:
self.x = x
if y < 0:
self.y = 0
elif y > self.maxY:
self.y = self.maxY
else:
self.y = y
#print self.x, self.y
autopy.mouse.move(self.x,self.y)
def moveBy(self, x, y):
"""moves coursor by x step and y step"""
self.moveTo(self.x + x, self.y + y)
def leftButtonDown(self):
"""makes left button of mouse pushed"""
autopy.mouse.toggle(True,autopy.mouse.LEFT_BUTTON)
def leftButtonUp(self):
"""makes left button of mouse unpushed"""
autopy.mouse.toggle(False,autopy.mouse.LEFT_BUTTON)
def leftClick(self):
self.leftButtonDown()
self.leftButtonUp()
def doubleLeftClick(self):
self.leftClick()
self.leftClick()
def rightButtonDown(self):
"""makes right button of mouse pushed"""
autopy.mouse.toggle(True,autopy.mouse.RIGHT_BUTTON)
def rightButtonUp(self):
"""makes right button of mouse unpushed"""
autopy.mouse.toggle(False,autopy.mouse.RIGHT_BUTTON)
def rightClick(self):
self.rightButtonDown()
self.rightButtonUp()
def doubleRightClick(self):
self.rightClick()
self.rightClick()