码迷,mamicode.com
首页 > 其他好文 > 详细

模拟鼠标键盘,查看鼠标在屏幕的位置

时间:2020-07-24 16:06:53      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:==   range   sleep   and   style   模拟   import   开始   失败   

 1 # 案例获取鼠标的位置,方便复制我们定位的鼠标坐标点到代码中
 2 import pyautogui
 3 import time
 4 
 5 # 获取鼠标位置
 6 def get_mouse_positon():
 7   time.sleep(5) # 准备时间
 8   print(‘开始获取鼠标位置‘)
 9   try:
10     for i in range(10):
11       # Get and print the mouse coordinates.
12       x, y = pyautogui.position()
13       positionStr = ‘鼠标坐标点(X,Y)为:{},{}‘.format(str(x).rjust(4), str(y).rjust(4))
14       pix = pyautogui.screenshot().getpixel((x, y)) # 获取鼠标所在屏幕点的RGB颜色
15       positionStr += ‘ RGB:(‘ + str(pix[0]).rjust(3) + ‘,‘ + str(pix[1]).rjust(3) + ‘,‘ + str(pix[2]).rjust(
16         3) + ‘)‘
17       print(positionStr)
18       time.sleep(0.5) # 停顿时间
19   except:
20     print(‘获取鼠标位置失败‘)
21 
22 
23 if __name__ == "__main__":
24   get_mouse_positon()

 

模拟鼠标键盘,查看鼠标在屏幕的位置

标签:==   range   sleep   and   style   模拟   import   开始   失败   

原文地址:https://www.cnblogs.com/chunfang/p/13371078.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!