【发布时间】:2020-08-29 01:39:40
【问题描述】:
我的目标是在用户输入的任何位置显示工具提示。为此,我需要找到插入符号的位置(用户输入的位置)。我正在使用 Windows 10 和 Python 3.8。基于this thread,我尝试了以下代码:
import win32gui
import win32process
import win32api
fg_win = win32gui.GetForegroundWindow()
fg_thread, fg_process = win32process.GetWindowThreadProcessId(fg_win)
current_thread = win32api.GetCurrentThreadId()
win32process.AttachThreadInput(current_thread, fg_thread, True)
try:
print(win32gui.GetCaretPos())
finally:
win32process.AttachThreadInput(current_thread, fg_thread, False) #detach
无论插入符号实际在哪里,代码都会打印 0,0。如何获取屏幕上插入符号的位置?
【问题讨论】:
-
不支持从 Python 可靠地使用
AttachThreadInput的方法。损失不大,因为无论如何它都不是您解决方案的一部分。请改用WinEvents。
标签: python windows winapi pywin32 win32gui