Copy tooltip text under mouse cursor?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bitbuerster
Posts: 5
Joined: 11 Dec 2023, 08:42

Copy tooltip text under mouse cursor?

11 Dec 2023, 08:57

Hi

When one hovers the mouse over an embedded URI (be it in Outlook, Word, PDFs, Chrome/FF/Edge, ..<your-favorite-application>), a tooltip displays some text.
Often, I can't do a right-click and copy that text then. So I'd like to write an AHK script to do the job: The idea is to define a hotkey (say Win-C) that when pressed, copies the mouse's current tooltip text into the clipboard.
(And of course, if no tooltip is active, also nothing is copied).

-Any hints if/how this is possible in AutoHotKey?

Thx for help
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Copy tooltip text under mouse cursor?

11 Dec 2023, 10:19

Welcome to this AutoHotkey forum!

Code: Select all

; This script gets tooltip text
#Requires AutoHotkey v1.1.33

#If WinExist("ahk_class tooltips_class32")
#c::
ControlGetText A_Clipboard
MsgBox 64, Clipboard, % A_Clipboard
Return
#If
bitbuerster
Posts: 5
Joined: 11 Dec 2023, 08:42

Re: Copy tooltip text under mouse cursor?

11 Dec 2023, 14:18

mikeyww wrote:
11 Dec 2023, 10:19
; This script gets tooltip text
Thanks, but this doesn't work:
When I use WindowSpy.ahk, I see that the respective ahk_class "tooltips_class32" is never triggered:
- in FireFox, the ahk_class sticks at "MozillaWindowClass",
- in Chrome and Edge, ahk_class both stays "Chrome_WidgetWin_1"
- in PDF-XChange-Viewer, ahk_class stays "DSUI:PDFXCViewer"

That is: No matter whether a tooltip shows up at my mouse-cursor or not, this "tooltips_class32" is not shown as ahk_class, so the script can not trigger on it.
(Could it be that the tooltip window is ..well, how to say.. "not active enough"?)
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Copy tooltip text under mouse cursor?

11 Dec 2023, 15:19

So change the script to match the tip!

That's about all that I know about this one.
bitbuerster
Posts: 5
Joined: 11 Dec 2023, 08:42

Re: Copy tooltip text under mouse cursor?

12 Dec 2023, 07:28

mikeyww wrote:
11 Dec 2023, 15:19
So change the script to match the tip!
I can't: In the very moment that you actually want to move the mouse to the tooltip, you move it away from the URI that triggered the tooltip. So it vanishes before the tooltip gets respective focus.
BTW: Your code works for the tooltips that Windows itself shows in its taskbar.
-Seems I have to dig deeper if there is something like a tree of all windows (active and non-active) that one could parse to check for a tooltip class one..

Anyway, tnx for your help
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: Copy tooltip text under mouse cursor?

12 Dec 2023, 07:41

What you said is basically correct. You can’t use Window Spy to see the window class of a tooltip. What it’s showing you is the underlying window because the mouse pointer never can hover over a tooltip by its nature. That doesn’t mean you can’t get the window class of a tooltip. As you suggested, you can write a script to always display the window classes of all existing windows, and you see which new one appears when a tooltip appears, for example.

Having said that, if a tooltip isn’t a standard Windows tooltip with which mikeyww’s script would work, the tooltip is typically not its own window at all but is a special widget rendered by the application from which you can’t grab the text in this manner.
GEV
Posts: 1005
Joined: 25 Feb 2014, 00:50

Re: Copy tooltip text under mouse cursor?

12 Dec 2023, 12:12

In Firefox i found a window of class MozillaDropShadowWindowClass whose title is the tooltip:

Code: Select all

#IfWinActive ahk_exe firefox.exe

	#c::
		If WinExist("ahk_class MozillaDropShadowWindowClass")
		{
			WinGetTitle, WinTitle, ahk_class MozillaDropShadowWindowClass
			MsgBox, % WinTitle
		}
	return
bitbuerster
Posts: 5
Joined: 11 Dec 2023, 08:42

Re: Copy tooltip text under mouse cursor?

14 Dec 2023, 17:55

boiler wrote:
12 Dec 2023, 07:41
Having said that, if a tooltip isn’t a standard Windows tooltip with which mikeyww’s script would work, the tooltip is typically not its own window at all but is a special widget rendered by the application from which you can’t grab the text in this manner.
Interesting.. -I'm far from being a Windows expert, so please tell me where I am wrong: I'd expect that if it is like you say that the tooltip is not a window of its own, that would mean that the respective window has that widget as a control in it? (Because if so, one could try to find & read out that one)

Now I tried it along the example #3 from https://www.autohotkey.com/docs/v1/lib/WinGet.htm#ControlList therefore to read out the Controls of that active window where the tooltip pops up:

Code: Select all

#c::
return
WinGet, ActiveControlList, ControlList, A
Loop, Parse, ActiveControlList, `n
{
    MsgBox, 4,, Control #%A_Index% is "%A_LoopField%". Continue?
    IfMsgBox, No
        break
}
But in the Outlook-window where I tried that, the ActiveControlList I receive is always 133 items long -no matter whether I invoke the script on a tooltip being displayed in that window or not.
So: If the tooltip is not to be found in that list of "controls" of a window -where is it then? :think:
bitbuerster
Posts: 5
Joined: 11 Dec 2023, 08:42

Re: Copy tooltip text under mouse cursor?

14 Dec 2023, 18:07

GEV wrote:
12 Dec 2023, 12:12
In Firefox i found a window of class MozillaDropShadowWindowClass whose title is the tooltip:
Yep -this is exactly what I'm looking for! -Just that it works only for FF, leaving open a solution for Outlook, Chrome/Edge and the other apps.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: bobstoner289, Ralf_Reddings200244 and 303 guests