Python获取鼠标位置的句柄

发布时间 2023-06-27 15:14:32作者: zwnsyw
import time

import win32gui
import win32api


# 获取当前鼠标【x y】坐标
time.sleep(2)
print("2秒内移动鼠标到对应窗口")
point = win32api.GetCursorPos()
print(point)

# 通过坐标获取坐标下的【窗口句柄】
hwnd = win32gui.WindowFromPoint(point)  # 请填写 x 和 y 坐标
print(hwnd)

title = win32gui.GetWindowText(hwnd)
print('窗口标题:%s' % (title))

 

参考链接:https://zhuanlan.zhihu.com/p/592658711

参考链接:https://blog.csdn.net/weixin_46625757/article/details/122498299