咔片PPT · AI自动生成演示文稿,模板丰富、排版精美 讯飞智文 · 一键生成PPT和Word,高效应对学习与办公

自动交易需要获取一些按键屏幕坐标, 用截屏然后在画笔中看坐标的方法可以实现, 但异常麻烦.

用下面这个程序, 可以实时显示坐标

import pyautogui as auto import time,os while True: # 获取屏幕的尺寸 screenWidth, screenHeight = auto.size() #返回鼠标的坐标 x, y = auto.position() print(f'屏幕尺寸: ({screenWidth} {screenHeight}), 鼠标坐标 : ({x}, {y})') time.sleep(0.01) #等待0.01秒 os.system('clear') #mac系统用clear, win用cls

如果不想读取屏幕大小, 上面的程序可以简化为:

import pyautogui as auto import time,os while True: x, y = auto.position() #返回鼠标的坐标 print(f'鼠标坐标 : ({x}, {y})') time.sleep(0.01) #等待0.01秒 os.system('clear') #mac系统用clear, win用cls

如果不想频繁刷新屏幕可以少导入一个os库, 可以

import pyautogui as auto import time while True: x, y = auto.position() print(f'鼠标坐标 : ({x}, {y})r',end="") time.sleep(0.01)

python还是不错的