目录
使用外部库PyMouse
1.安装依赖库xlib
2.安装pymouse库
3. 测试安装是否成功
4.代码
安装pymouse必须要xlib的支持,所以先安装xlib依赖库
1 sudo apt-get install python-xlib
View Code
1 sudo pip install pymouse
View Code
注意:千万不要在xshell或者putty远程连接下面进行测试,因为xshell和putty等远程连接软件没有界面功能,所以无法测试。一般在vnc中测试。
#coding:utf-8
import time
from pymouse import PyMouse
m=PyMouse()
value = m.position()
print("position:",value)
def powerOff():
m.move(815,362)
m.click(815,362)
print("power off!")
def powerOn():
m.move(1115,397)
m.click(1115,397)
print("power on!")
def backHome():
m.move(787,487)
m.click(787,487)
print("back home!")
def leaveHome():
m.move(1401,385)
m.click(1401,385)
print("leave home!")
while 1:
powerOn()
i=0
while i<30:
backHome()
time.sleep(5)
leaveHome()
time.sleep(5)
powerOff()
auto_mouse.py
#coding:utf-8
import time
from pymouse import PyMouse
y1 = 410
y2 = 500
x1 = 700
x2 = 1000
x3 = 1400
m=PyMouse()
value = m.position()
print("position:",value)
def powerOff():
m.move(x2,y1)
m.click(x2,y1)
print("power off!")
def powerOn():
m.move(x1,y1)
m.click(x1,y1)
print("power on!")
def backHome():
m.move(x2,y1)
m.click(x2,y1)
print("back home!")
def leaveHome():
m.move(x2,y2)
m.click(x2,y2)
print("leave home!")
def sleepMode():
m.move(x3,y2)
m.click(x3,y2)
print("sleepMode!")
def meeting():
m.move(x3,y1)
m.click(x3,y1)
print("meeting!")
while 1:
powerOn()
time.sleep(60)
i=0
while i<30:
print("------ count: {0:2d} --------" ).format(i)
backHome()
time.sleep(5)
leaveHome()
time.sleep(5)
meeting()
time.sleep(5)
sleepMode()
time.sleep(5)
i=i+1
powerOff()
time.sleep(10)
mousePosDetect.py
#coding:utf-8
from pymouse import PyMouse
while 1:
m=PyMouse()
value = m.position()
print("position:",value)