Tomshi wrote: ↑23 Mar 2023, 04:22
Simply calling the tooltip function constantly is a bad idea, if the user's mouse coord hasn't changed you can end up with flickering which isn't ideal.
Good point, so I updated the function.
Code: Select all
ToolTipX(Text?, TimeOut := 5, EnableToggle := false, WhichToolTip?, *)
@param {any} Text
If omitted, the existing tooltip and its timer (if any) will be closed. Otherwise, this parameter is the text to display in the tooltip.
@param {number} TimeOut
The tooltip will be hidden after the set number of seconds.
If you do not want the tooltip to be hidden automatically after a timeout, set this parameter to
0.
@param {number} enableToggle
Allow to show/hide a tooltip with the same hotkey.
If the tooltip has been automatically hidden due to a timeout, the toggle status will switch to off as well.
To update the content of a tooltip that is currently shown on the screen, set this parameter to
false (or
0).
You can still manually turn off the tooltip before the timeout by omitting all parameters like this: ToolTipX()
@param {number} WhichToolTip
Omit this parameter if you don't need multiple tooltips to appear simultaneously.
Otherwise, this is a number between 1 and 20 to indicate which tooltip window to operate upon.
If unspecified, that number is 1 (the first).
@returns {void}
Code: Select all
/**
* Creates a Pop-up Tooltip window that follows the mouse movement.
* @param {any} Text
* If omitted, the existing tooltip (if any) will be hidden. Otherwise,
* this parameter is the text to display in the tooltip.
* @param {number} TimeOut
* The tooltip will be hidden after the set number of seconds.
* If you do not want the tooltip to be hidden automatically after a timeout, set this parameter to 0.
* @param {number} enableToggle
* Allow to show/hide a tooltip with the same hotkey.
* If the tooltip has been automatically hidden due to a timeout, the toggle status will switch to off as well.
* @param {number} WhichToolTip
* Omit this parameter if you don't need multiple tooltips to appear simultaneously.
* Otherwise, this is a number between 1 and 20 to indicate which tooltip window to operate upon.
* If unspecified, that number is 1 (the first).
* @returns {void}
*/
ToolTipX(Text?, TimeOut := 5, EnableToggle := false, WhichToolTip?, *)
{
Static Toggle := false
if !IsSet(Text) || !(Toggle := !Toggle)
{
SetTimer(Updating, 0),
ToolTip(,,, WhichToolTip?)
if EnableToggle || !IsSet(Text)
return
}
ttw := ToolTip(Text?, , , WhichToolTip?),
anchorPt := Buffer(8), winRect := Buffer(16),
excludeRect := Buffer(16), outRect := Buffer(16),
winSize := winRect.ptr+8,
flags := (VerCompare(A_OSVersion, "6.2") < 0 ? 0 : 0x10000),
tick := A_TickCount,
SetTimer(Updating, -1)
Updating()
{
if (A_TickCount-tick > TimeOut*1000) || (EnableToggle && !Toggle)
{
ToolTip(,,,WhichToolTip?),
Toggle := 0
return
}
SetWinDelay(-1),
CoordMode("Mouse", "Screen"),
MouseGetPos(&x, &y),
NumPut("int", x+16, "int", y+16, anchorPt),
NumPut("int", x-3, "int", y-3, "int", x+3, "int", y+3, excludeRect),
DllCall("GetClientRect", "ptr", ttw, "ptr", winRect),
DllCall("CalculatePopupWindowPosition", "ptr", anchorPt, "ptr", winSize, "uint", flags, "ptr", excludeRect, "ptr", outRect)
Try WinMove(NumGet(outRect, 0, 'int'), NumGet(outRect, 4, 'int'),,, ttw)
Catch
Return
Else SetTimer(, -1)
}
}
Inspired by lexikos's original post here: https://www.autohotkey.com/boards/viewtopic.php?p=459758&sid=0df64ba643e477797d43e1db32dd6b69#p459758