[V2] Tooltip2 to follow mouse with timeout
Posted: 22 Mar 2023, 06:28
I have created a function to display the tooltip that follows the mouse and stops after a time.
Strange that I could not find it on the forum for V2, or I missed some forums.
Maybe a nice example for in the Tooltip documentation?
UPDATED:
- Switched to use A_TickCount to determine the TargetTime
- Modified Simplefied to eliminate flickering
Here is the identical script, but simplified, as this is more readable to understand for educational purposes.
Fat arrow functions are efficient, but not always readable.
Maybe this version is more suited as an example in the documentation.
Question: Does somebody has a better/shorter version? I would love to imp
Strange that I could not find it on the forum for V2, or I missed some forums.
Maybe a nice example for in the Tooltip documentation?
UPDATED:
- Switched to use A_TickCount to determine the TargetTime
- Modified Simplefied to eliminate flickering
Code: Select all
#Requires AutoHotkey v2.0-rc.2
ToolTip2(Text?, TimeSeconds:=5, WhichToolTip?){
; Shows a Tooltip following the mouse for a specified time
SetTimer(((Text?,TickCountTarget?,WhichToolTip?)=>( (TickCountTarget<A_TickCount) ? (ToolTip("",,,WhichToolTip?), SetTimer(,0)) : (ToolTip(Text?,,,WhichToolTip?)))).Bind(Text?,A_TickCount+TimeSeconds*1000,WhichToolTip?), 50)
}
Here is the identical script, but simplified, as this is more readable to understand for educational purposes.
Fat arrow functions are efficient, but not always readable.
Maybe this version is more suited as an example in the documentation.
Code: Select all
#Requires AutoHotkey v2.0-rc.2
ToolTip2_Simplefied(Text?, TimeSeconds:=5, WhichToolTip?){
SetTimer(ToolTipSub.Bind(Text?, A_TickCount+TimeSeconds*1000, WhichToolTip?), 50)
X_Mouse_Prev := ""
Y_Mouse_Prev := ""
ToolTipSub(Text?, TimeTarget?, WhichToolTip?){
if (A_TickCount>TimeTarget){
ToolTip("",,,WhichToolTip?)
SetTimer(,0)
} else {
MouseGetPos(&X_Mouse, &Y_Mouse)
if (X_Mouse_Prev!=X_Mouse or Y_Mouse_Prev!=Y_Mouse){
ToolTip(Text?,,,WhichToolTip?)
X_Mouse_Prev := X_Mouse
Y_Mouse_Prev := Y_Mouse
}
}
}
}