分享几个找图得坐标的方法

import win32gui
import pyautogui
hwnd = 窗口句柄
def windows_point(hwnd):
    # 获取已知窗口句柄的窗口屏幕的左上点坐标和右下点坐标
    post =win32gui.GetWindowRect(hwnd)
    x1 = post[0]
    y1 = post[1]
    x2 = post[2]
    y2 = post[3]
    return x1,y1,x2,y2

def get_windows_point(hwnd,name):
    # 在整个屏幕上找图(中心点),并和窗口屏幕相运算,得到窗口中相对坐标
    post = win32gui.GetWindowRect(hwnd)
    x1 = post[0]
    y1 = post[1]
    image = pyautogui.locateCenterOnScreen(f'path/{name}.PNG', confidence=0.9)
    x = image[0]-x1
    y = image[1]-y1

    return x,y

def get_windows_conter_point_and_click(hwnd,click_num):
    # 获取已知窗口句柄的窗口屏幕在整个屏幕上中心点的坐标位置,并点击设置次数
    post = win32gui.GetWindowRect(hwnd)
    x1 = post[0]
    y1 = post[1]
    x2 = post[2]
    y2 = post[3]
    x3 = int(x1+(x2-x1)/2)
    y3 = int(y1+(y2-y1)/2)
    pyautogui.click(x3,y3,click_num)

暂时一些小想法,如有大佬能够优化,请一起在评论区交流交流,谢谢!

  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值