pyautogui的鼠标函数使用x,y坐标,原点在屏幕左上角,向右x坐标增加,向下y坐标增加,所有坐标都是正整数,没有负数坐标。
使用pip安装
python源码
import time,os
import pyautogui as pag
try:
while True:
print('点击 Ctrl-C 结束')
# 获取屏幕的尺寸
screenWidth, screenHeight = pag.size()
x, y = pag.position()
#返回鼠标的坐标
print('屏幕尺寸: (%s %s), 鼠标坐标 : (%s, %s)' % (screenWidth, screenHeight, x, y))
# 每个1s中打印一次 , 并执行清屏
time.sleep(1)
# 执行系统清屏指令
os.system('cls')
except KeyboardInterrupt:
print('结束')
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
执行结果
运行结果
脚本思路大概如下:第一步获取整个屏幕尺寸,第二步获取鼠标坐标,打印输出即可,整个获取过程在死循环中,即可实现时刻获取屏幕坐标的需求。
def coordinate(x, y):
if x>0:
if y>0:
a = 1
else:
a = 2
else:
if y>0:
a = 3
else:
a = 4
return a #根据x,y返回aif __name__ == "__main":
print 'Please insert X,Y'
x = input('Please insert X')
y = input('Please insert Y')
print coordinate(x,y)
[python] view plain copy print?<span style="font-family: Arial, Helvetica, sans-serif">>>>import numpy as np</span>[python] view plain copy print?>>>import matplotlib.pyplot as plt>>>x=np.arange(-5,5,0.01)>>>y=x**3>>>plt.axis([-6,6,-10,10])[-6, 6, -10, 10]>>>plt.plot(x,y)[<matplotlib.lines.Line2D object at 0x03C642B0>]>>>plt.show()画出来的图形如下:另外坐标轴坐标区间设定还有另一种方法:[python] view plain copy print?xlim((xmin,max)) #设置坐标轴的最大最小区间xlim(xmin,xmax) #设置坐标轴的最大最小区间ylim((ymin,ymax))#设置坐标轴的最大最小区间ylim(ymin,ymax) #设置坐标轴的最大最小区间所以下面:[python] view plain copy print?>>>import numpy as np>>>import matplotlib.pyplot as plt>>>x=np.arange(-5,5,0.01)>>>y=x**3>>>plt.xlim(-6,6)(-6, 6)>>>plt.ylim(-500,500)(-500, 500)>>>plt.plot(x,y)[<matplotlib.lines.Line2D object at 0x0381A4B0>]>>>plt.show()则图形为:很明显,图形的坐标区间改变了!自己可以根据喜好或需求修改区间。