有没有办法获取鼠标光标下方的窗口的名称(即鼠标光标悬停的窗口(?窗口不一定是活动窗口。
在我的代码中,我有一个函数,每次用户按 F2 时都会运行。
我希望这个函数运行,只有当鼠标悬停在镶边窗口上时。
有什么想法吗?
在python中使用Pynput和Win32 API:(对我来说很好用!(
from pynput import mouse
from win32gui import GetWindowText, GetCursorPos, WindowFromPoint
def on_move(x, y):
print(GetWindowText(WindowFromPoint(GetCursorPos())))
# Collect events until released
with mouse.Listener(on_move=on_move) as listener:
listener.join()
不要忘记安装:pip install pynput
和pip install win32gui