Page 1 of 1

ToolTip duration problem

Posted: 28 Mar 2019, 03:40
by SL5
I have a problem with the duration of a tooltip.
ToolTip,% A_LineNumber
Sleep,3000 ; time for reading
These should actually be readable for three seconds but are gone immediately.

Code: Select all

SetTitleMatchMode,2
DetectHiddenWindows,On
token = 1903280913
while(1){
	ToolTip2sec( token " : 2 seconds `n(" A_ThisFunc " " RegExReplace(A_LineFile,".*\\") ":"  A_LineNumber ")",1,1 )
	Sleep,1900
	IfWinNotExist,% token
	{
		ToolTip,% A_LineNumber
		SoundBeep,5000
		MsgBox,262160,% ":(`n" A_ThisFunc ":" A_LineNumber " " RegExReplace(A_LineFile, ".*\\") ,% ":(`n(" A_ThisFunc ":" A_LineNumber " " RegExReplace(A_LineFile, ".*\\") ")"
	}else{
		ToolTip,% A_LineNumber
		; SoundBeep,8000
	}
	Sleep,3000 ; time for reading
	
	Sleep,300
	IfWinExist,% token
	{
		ToolTip,% A_LineNumber
		SoundBeep,5000
		MsgBox,262160,% ":(`n" A_ThisFunc ":" A_LineNumber " " RegExReplace(A_LineFile, ".*\\") ,% ":(`n(" A_ThisFunc ":" A_LineNumber " " RegExReplace(A_LineFile, ".*\\") ")"
	}else{
		ToolTip,% A_LineNumber
		; SoundBeep,8000
	}
	Sleep,3000 ; time for reading
	Reload
	
}	

RemoveToolTip_level2(){
                   	ToolTip, , , , 2
                   	RemoveToolTip_level2Obj := Func("RemoveToolTip_level2")
                   	SetTimer % RemoveToolTip_level2Obj, , Off
                   	return
                   }

;/¯¯¯¯ ToolTipSec ¯¯ 190110154314 ¯¯ 10.01.2019 15:43:14 ¯¯\
ToolTipSec(t,x=123,y=321,sec=1000,layer1to20:=1)  {
    Last_A_This:=A_ThisFunc . A_ThisLabel
   ; lll(A_LineNumber, "ToolTipSec.inc.ahk",Last_A_This)

    MouseGetPos,xMouse,yMouse
    ; t := regexReplace(t,",",".") ;
    ; t := regexReplace(t,"+","#") ;
  if( x=123 AND y=321 )
  {
  	ToolTip, %t% , 0, % yMouse + 10, layer1to20
   ; lll(A_LineNumber, "ToolTipSec.inc.ahk")
  }
  else
  {
    ;  lll(A_LineNumber, "ToolTipSec.inc.ahk")
      if(abs(yMouse - y ) < 90 ){
        y := ( y < 500 ) ? (y+150) : (y-150)
      }
	  ToolTip, %t%,%x%,%y%, layer1to20
      ;~ MsgBox,ToolTip %t% %x% %y%
      ;
  }


  ; http://www.autohotkey.com/board/topic/81732-try-catch-doesnt-work/
  ;~ .. but here's how to suppress load-time "function not found" errors:
  blank := ""
  ;~ commaBlank := ", "
  ;~ if(isFunc("RemoveToolTip") )
  ;~ RemoveToolTip%blank%( sec )
  ; SetTimer,RemoveToolTip%layer1to20%,%sec%

  ; SetTimer,RemoveToolTip_level%layer1to20%,%sec%
  	RemoveToolTip_level1Obj := Func("RemoveToolTip_level" layer1to20)
  	; pause
  	SetTimer, % RemoveToolTip_level1Obj, ,Off

  ;~ kkk
  ;~ RemoveToolTip( sec )
  ;~ ; jj
  
  ;~ empty:="Timer"
  ;~ Set%empty%,
  return
}
;\____ ToolTipSec __ 190328093749 __ 28.03.2019 09:37:49 __/

ToolTip1sec(t,x=123,y=321, layer1to20:=1){
  Last_A_This:=A_ThisFunc . A_ThisLabel
  ;~ lll(A_LineNumber, "ToolTipSec.inc.ahk",Last_A_This)
  ToolTipSec(t,x,y,1000, layer1to20)
  return
}


ToolTip2sec(t,x=123,y=321, layer1to20:=1){
Last_A_This:=A_ThisFunc . A_ThisLabel
  ;~ lll(A_LineNumber, "ToolTipSec.inc.ahk",Last_A_This)
  ToolTipSec(t,x,y,2000, layer1to20)
  return
}

ToolTip3sec(t,x=123,y=321, layer1to20:=1){
Last_A_This:=A_ThisFunc . A_ThisLabel
  ;lll(A_LineNumber, "ToolTipSec.inc.ahk",Last_A_This)

  ToolTipSec(t,x,y,3000, layer1to20)
  return
}

ToolTip4sec(t,x=123,y=321, layer1to20:=1){
Last_A_This:=A_ThisFunc . A_ThisLabel
  ;lll(A_LineNumber, "ToolTipSec.inc.ahk",Last_A_This)

  ToolTipSec(t,x,y,4000, layer1to20)
  return
}

ToolTip5sec(t,x=123,y=321, layer1to20:=1){
  ToolTipSec(t,x,y,5000, layer1to20)
  Last_A_This:=A_ThisFunc . A_ThisLabel
  lll(A_LineNumber, "ToolTipSec.inc.ahk",Last_A_This)
  return
}

ToolTip6sec(t,x=123,y=321, layer1to20:=1){
  ToolTipSec(t,x,y,6000, layer1to20)
  Last_A_This:=A_ThisFunc . A_ThisLabel
  lll(A_LineNumber, "ToolTipSec.inc.ahk",Last_A_This)
  return
}

ToolTip7sec(t,x=123,y=321, layer1to20:=1){
  ToolTipSec(t,x,y,7000, layer1to20)
  Last_A_This:=A_ThisFunc . A_ThisLabel
  lll(A_LineNumber, "ToolTipSec.inc.ahk",Last_A_This)
  return
}

ToolTip8sec(t,x=123,y=321, layer1to20:=1){
  ToolTipSec(t,x,y,8000, layer1to20)
  Last_A_This:=A_ThisFunc . A_ThisLabel
  lll(A_LineNumber, "ToolTipSec.inc.ahk",Last_A_This)
  return
}

;/¯¯¯¯ ToolTip9sec ¯¯ 190110154202 ¯¯ 10.01.2019 15:42:02 ¯¯\
ToolTip9sec(t,x=123,y=321, layer1to20:=1){
  ToolTipSec(t,x,y,9000, layer1to20)
  Last_A_This:=A_ThisFunc . A_ThisLabel
  lll(A_LineNumber, "ToolTipSec.inc.ahk",Last_A_This)
  return
}
;\____ ToolTip9sec __ 190110154205 __ 10.01.2019 15:42:05 __/


Re: ToolTip duration problem

Posted: 28 Mar 2019, 04:04
by Kobaltauge
Does the Tooltip vanish because "another command" is executed?
Your two line code works on my computer.

Re: ToolTip duration problem

Posted: 28 Mar 2019, 04:09
by SL5
Kobaltauge wrote:
28 Mar 2019, 04:04
Does the Tooltip vanish because "another command" is executed?
Your two line code works on my computer.
I mean the scrypt that I have inserted below that obove is just an explanation.

Re: ToolTip duration problem

Posted: 28 Mar 2019, 04:19
by Blue Kodiak

Code: Select all

Tooltip , Display-This
SetTimer , ClearToolTip , 3000

.....other stuff.....

ClearToolTip:
Tooltip
SetTimer , ClearToolTip , Off
Return

Re: ToolTip duration problem

Posted: 28 Mar 2019, 04:59
by just me
What confusing code for such a simple task! :shock:

Besides the fact that your code snippet does not run without changes, it does what I expect. What are you missing?

Re: ToolTip duration problem

Posted: 28 Mar 2019, 05:02
by SL5
Blue Kodiak wrote:
28 Mar 2019, 04:19

Code: Select all

Tooltip , Display-This
SetTimer , ClearToolTip , 3000

.....other stuff.....

ClearToolTip:
Tooltip
ClearToolTip , Off
Return
no, your example works quite differently.
in my example, only certain types of tooltips are removed.
that is the last parameter in the tooltip you can use about twenty different ones.
ToolTip, , , , 20
ToolTip, , , , 19
your example probably corresponds to the following:
ToolTip, , , , 1
Tooltip

Re: ToolTip duration problem

Posted: 28 Mar 2019, 05:51
by Blue Kodiak
^ It was just an example of how to do it.

Code: Select all

[i]....some-stuff....[/i]
Tooltip , Display-This, , ,1
SetTimer , ClearToolTip1 , 3000
[i]....more-stuff....[/i]
Tooltip , Different-Message, , ,2
SetTimer , ClearToolTip2 , 4000
[i].....other stuff.....[/i]
.... .... .... .... ....
Tooltip , Another-Message, , ,20
SetTimer , ClearToolTip20 , 5000

... ...
... ...

ClearToolTip1:
  ClearToopTip(1)
  Return

ClearToolTip2:
  ClearToopTip(2)
  Return
...
...
ClearToolTip20:
  ClearToolTip(20)
  Return

... ...
... ...

ClearToolTip(TT)
Tooltip, , , , TT
SetTimer , ClearToolTip%TT% , Off
TT =
Return

Re: ToolTip duration problem

Posted: 28 Mar 2019, 06:00
by SL5
Blue Kodiak wrote:
28 Mar 2019, 05:51
^ It was just an example of how to do it.

Code: Select all

[i]....some-stuff....[/i]
Tooltip , Display-This, , ,1
SetTimer , ClearToolTip1 , 3000
[i]....more-stuff....[/i]
Tooltip , Different-Message, , ,2
SetTimer , ClearToolTip2 , 4000
[i].....other stuff.....[/i]
.... .... .... .... ....
Tooltip , Another-Message, , ,20
SetTimer , ClearToolTip20 , 5000

... ...
... ...

ClearToolTip1:
  ClearToopTip(1)
  Return

ClearToolTip2:
  ClearToopTip(2)
  Return
...
...
ClearToolTip20:
  ClearToolTip(20)
  Return

... ...
... ...

ClearToolTip(TT)
Tooltip, , , , TT
SetTimer , ClearToolTip%TT% , Off
TT =
Return
okay I give you some background information:

the advantage of my new features is that they are only one line long and the remove is automatically included.

I've been using it for years and it worked very well.

Due to a change, however, something seems to function incorrectly over time.

Re: ToolTip duration problem

Posted: 28 Mar 2019, 07:04
by just me
What your code in the OP does:

Code: Select all

ToolTip2sec( token " : 2 seconds `n(" A_ThisFunc " " RegExReplace(A_LineFile,".*\\") ":"  A_LineNumber ")",1,1 )
calls

Code: Select all

ToolTipSec(t,x,y,2000, layer1to20)
which shows the tooltip 1.

Code: Select all

SetTimer, % RemoveToolTip_level1Obj, ,Off
doesn't set a timer so the tooltip will stay until it will be overwritten.

If you had set a timer of 2000 ms to remove the first tooltip, your script would work as follows:

Code: Select all

#NoEnv
ToolTip, First tooltip shown for 2000 ms!
SetTimer, RemoveTT, -2000
Sleep, 1900
ToolTip, Second tooltip shown for 3000 ms!
Sleep, 3000
MsgBox, 3000 ms are over now!
ExitApp
RemoveTT:
ToolTip
Return
IMO, it makes no sense to use a timer for a tooltip if you need to sleep to prevent the script from continuing anyway.

Re: ToolTip duration problem

Posted: 28 Mar 2019, 08:23
by SL5
I think I should explain it better (Screensho). This show that ToolTip2sec(t,x=123,y=321, layer1to20:=1) works => https://youtu.be/d8Dw0oVC_Ek

Code: Select all

RemoveToolTip_level2(){
	ToolTip, , , , 2
	TemoveToolTip_level2Obj := Func("RemoveToolTip_level2")
	SetTimer, % RemoveToolTip_level2Obj, , Off
	SoundBeep,1800,200
	return
}
ToolTip2sec(t,x=123,y=321, layer1to20:=1){
	Last_A_This:=A_ThisFunc . A_ThisLabel
  ;~ lll(A_LineNumber, "ToolTipSec.inc.ahk",Last_A_This)
  SoundBeep,2000,400
	ToolTipSec(t,x,y,2000, layer1to20)
	return
}


Re: ToolTip duration problem

Posted: 28 Mar 2019, 09:57
by just me
I try to explain it better, too. As far as I understand your code snippet:
  1. ToolTip2sec() shows a ToolTip-1, sets a timer to remove the Tooltip after 2 seconds / 2000 milliseconds, and returns immediately.
  2. Sleep, 1900 delays further execution for 1900 milliseconds.
  3. IfWinNotExist,% token is executed about 100 milliseconds before the timer set in 1. will be triggered. It overwrites the existing ToolTip-1 with new text either in the If or in the Else branch.
  4. Sleep,3000 ; time for reading is executed now. If it is executed before the remaining 100 milliseconds for the timer have passed, the timer will be called after a very short delay and Tooltip-1 will be destroyed during the sleep time.
Related code in the OP:

Code: Select all

while(1){
	ToolTip2sec( token " : 2 seconds `n(" A_ThisFunc " " RegExReplace(A_LineFile,".*\\") ":"  A_LineNumber ")",1,1 )
	Sleep,1900
	IfWinNotExist,% token
	{
		ToolTip,% A_LineNumber
		SoundBeep,5000
		MsgBox,262160,% ":(`n" A_ThisFunc ":" A_LineNumber " " RegExReplace(A_LineFile, ".*\\") ,% ":(`n(" A_ThisFunc ":" A_LineNumber " " RegExReplace(A_LineFile, ".*\\") ")"
	}else{
		ToolTip,% A_LineNumber
		; SoundBeep,8000
	}
	Sleep,3000 ; time for reading

Re: ToolTip duration problem

Posted: 28 Mar 2019, 10:27
by SL5
I'm sorry I asked that it was stupid. that makes you so much work.
I should have chosen the texts for the tooltips differently.

i changed ths texts a bit (sse below).

just before seid:

Code: Select all

; ToolTip, , , , 2
; ^--- in my understanding, only the tooltip of type number 2 is removed or overwritten with nothing
just me wrote:
28 Mar 2019, 09:57
... [*]IfWinNotExist,% token is executed about 100 milliseconds before the timer set in 1. will be triggered. It overwrites the existing ToolTip-1 with new text either in the If or in the Else branch.
[*]Sleep,3000 ; time for reading is executed now. If it is executed before the remaining 100 milliseconds for the timer have passed, the timer will be called after a very short delay and Tooltip-1 will be destroyed during the sleep time.[/list]
....

Code: Select all

SetTitleMatchMode,2
DetectHiddenWindows,On
token = 1903280913
while(1){
	ToolTip2sec( token " : 2 seconds `n(" A_ThisFunc " " RegExReplace(A_LineFile,".*\\") ":"  A_LineNumber ")",1,1 )
	Sleep,1500
	IfWinNotExist,% token
	{
		; #### this lines never visited by me. thats great
		ToolTip,% " 24 " A_LineNumber, 200, 1
		SoundBeep,5000
		MsgBox,262160,% ":(`n" A_ThisFunc ":" A_LineNumber " " RegExReplace(A_LineFile, ".*\\") ,% ":(`n(" A_ThisFunc ":" A_LineNumber " " RegExReplace(A_LineFile, ".*\\") ")"
	}else{
		ToolTip,% " 28 " A_LineNumber, 200, 1 ; <==== This was only very briefly displayed. i have expected 3000 millisec
		; thats becouse tooltip is detroy like this (timer): 
		; ToolTip, , , , 2
		; ^--- in my understanding, only the tooltip of type number 2 is removed or overwritten with nothing
		; ToolTip,% " 28 " ....
		; ^--- this would have to be type 1 and therefore not overwritten
		SoundBeep,3000,400 ; <== this is always beeping
	}
	Sleep,3000 ; time for reading


Re: ToolTip duration problem

Posted: 28 Mar 2019, 10:34
by SL5
if have found the error.

Code: Select all

ToolTip1sec(t,x=123,y=321, layer1to20:=1){
ToolTip2sec(t,x=123,y=321, layer1to20:=1){
expected:

Code: Select all

[code]
ToolTip1sec(t,x=123,y=321, layer1to20:=1){
ToolTip2sec(t,x=123,y=321, layer1to20:=2){
I had forgotten how I really programmed it :oops: thanks

Actually, it's not wrong, you just have to know how i did it

Re: ToolTip duration problem

Posted: 28 Mar 2019, 10:39
by just me

Code: Select all

ToolTip1sec(t,x=123,y=321, layer1to20:=1){
  Last_A_This:=A_ThisFunc . A_ThisLabel
  ToolTipSec(t,x,y,1000, layer1to20)
  return
}
ToolTip2sec(t,x=123,y=321, layer1to20:=1){
Last_A_This:=A_ThisFunc . A_ThisLabel
  ToolTipSec(t,x,y,2000, layer1to20)
  return
}
The only difference between the function is the duration, ToolTip1sec = 1000 ms, ToolTip2sec = 2000 ms.

Why should it be changed to

Code: Select all

ToolTip2sec(t,x=123,y=321, layer1to20:=2){ ; why should layer1to20 default to 2 here?
?

Re: ToolTip duration problem

Posted: 28 Mar 2019, 11:27
by SL5
just me wrote:
28 Mar 2019, 10:39
... The only difference between the function is the duration, ToolTip1sec = 1000 ms, ToolTip2sec = 2000 ms.
Why should it be changed to

Code: Select all

ToolTip2sec(t,x=123,y=321, layer1to20:=2){ ; why should layer1to20 default to 2 here?
?
yes your right. ich chached all to := 0 and used some algorithm with a var layer1to20_lastUsed

Code: Select all

ToolTip7sec(t,x=123,y=321, layer1to20:=0){
  ToolTipSec(t,x,y,7000, layer1to20)
  Last_A_This:=A_ThisFunc . A_ThisLabel
  lll(A_LineNumber, "ToolTipSec.inc.ahk",Last_A_This)
  return
}

ToolTip8sec(t,x=123,y=321, layer1to20:=0){
  ToolTipSec(t,x,y,8000, layer1to20)
  Last_A_This:=A_ThisFunc . A_ThisLabel
  lll(A_LineNumber, "ToolTipSec.inc.ahk",Last_A_This)
  return
}
I have now installed a global variable which always takes the next away from the last used one.
in this way, the likelihood of duration of duration of a tooptips is increased.
possible to have soem at the samt time (thats i oft using.)
2019-03-28 17_23_23-Einstellungen.png
(37.46 KiB) Downloaded 43 times

Code: Select all

ToolTipSec(t,x=123,y=321,sec=1000,layer1to20:=0)  {
    global layer1to20_lastUsed
    if(!layer1to20_lastUsed)
        layer1to20_lastUsed := 0
    if(!layer1to20){
        if(layer1to20_lastUsed < 20)
            layer1to20 := layer1to20_lastUsed + 1
        else
            layer1to20 := 1
    }
    layer1to20_lastUsed := layer1to20


Re: ToolTip duration problem

Posted: 28 Mar 2019, 15:35
by Blue Kodiak
This is what it seems to be doing:

Forever
Call ToolTip2sec with
text: token " : 2 seconds `n(" A_ThisFunc " " RegExReplace(A_LineFile ,".*\\") ":" A_LineNumber ")"
X coord: 1
Y coord: 1
Layer defaults to 1 as not passed
Call ToolTipSec passing the same arguments and also 2000 into the sec parameter. Note: the sec parameter is never used.
If the mouse Pointer is at a Y coord < 91 (remember passed Y coord is 1) set Y to 151. I think I got that right.
Display the passed text in Tooltip number 1 at Coords 1, 151
Set the variable 'blank' to an empty string, i.e., "". BUT then never reference it again
Get a reference to a user defined function RemoveToolTip_level1
NOTE: This function doesn't exist in the script so Func() will return 0, i.e., RemoveToolTip_level1Obj = 0
Turn Off the timer Labelled '0' (Which doesn't exist)
Return to ToolTip2sec
Return to Forever

Sleep for 1.9 seconds
Branch on windows existance
Both branches immediately display A_Linenumber in Tooltip 1
Sleep for 3 seconds
Hit snooze and sleep for an extra 0.3 seconds
Branch on window existence
Both branches immediately display A_Linenumber in Tooltip 1
Sleep for 3 seconds
Reload

Forever loop is not repeated becasue the script was reloaded

Re: ToolTip duration problem

Posted: 28 Mar 2019, 18:28
by SL5
Blue Kodiak wrote:
28 Mar 2019, 15:35
This is what it seems to be doing:

Forever
Call ToolTip2sec with
text: token " : 2 seconds `n(" A_ThisFunc " " RegExReplace(A_LineFile ,".*\\") ":" A_LineNumber ")"
X coord: 1
Y coord: 1
Layer defaults to 1 as not passed
Call ToolTipSec passing the same arguments and also 2000 into the sec parameter. Note: the sec parameter is never used.
If the mouse Pointer is at a Y coord < 91 (remember passed Y coord is 1) set Y to 151. I think I got that right.
Display the passed text in Tooltip number 1 at Coords 1, 151
Set the variable 'blank' to an empty string, i.e., "". BUT then never reference it again
Get a reference to a user defined function RemoveToolTip_level1
NOTE: This function doesn't exist in the script so Func() will return 0, i.e., RemoveToolTip_level1Obj = 0
Turn Off the timer Labelled '0'.
Return to ToolTip2sec
Return to Forever
.....
ohhh my god. thanks and sorry.

BTW if you interested in this forgoten function: