My goal is to display a tooltip wherever the user is typing. To do this, I need to find the location of the caret (the place where the user is typing). I'm using Windows 10 and Python 3.8. Based on this thread, I tried the following code:
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
The code prints 0,0 regardless of where the caret actually is. How can can I get the location of the caret on the screen?