很简单的代码,直接贴代码:

import os, time

import pyautogui as pag

try:
    while True:
        print("按下Ctrl + C 结束程序")
        # pag.position()返回鼠标的坐标
        x, y = pag.position()
        posStr = "当前鼠标位置:" + str(x).rjust(4) + ',' + str(y).rjust(4)
        # 打印当前鼠标位置坐标
        print(posStr)
        time.sleep(1)
        # 清除屏幕
        os.system('cls')
# 捕获异常 KeyboardInterrupt:用户中断执行(通常是输入^C)
except KeyboardInterrupt:
    print('已退出')

 

在Pycharm里运行 Ctrl C不能中断,是因为快捷键的存在,在cmd运行即可

Python - 利用pyautogui获取当前鼠标位置坐标

 

相关文章:

  • 2022-01-08
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-23
  • 2022-03-09
  • 2022-12-23
  • 2021-09-09
  • 2022-03-01
  • 2022-12-23
相关资源
相似解决方案