Timed Traytip

Get help with using AutoHotkey and its commands and hotkeys
c4p
Posts: 17
Joined: 18 Jan 2017, 18:38

Timed Traytip

08 Jun 2017, 13:47

The help file suggest the Traytip command display time "may vary from the one specified."
Using the example in the help file as a starting point, I was trying to brute force Traytips to display for the actual desired time.

Code: Select all

TrayTip(traytitle :="", traytext := "", traysecs := 3, trayoptions := "") {
  SetTimer, RemoveTrayTip, % (traysecs * -1000)
  SetTimer, RefreshTrayTip, 1000

  RefreshTrayTip:
  TrayTip, %traytitle%, %traytext%, %traysecs%, %trayoptions%
  return
   
  RemoveTrayTip:
  SetTimer, RefreshTrayTip, Off
  TrayTip
  
return
}
The traytip displays as you fall through the function the first time, but timer calls to RefreshTrayTip do not have the data within the traytext,etc (because the were local to the function). I tried declaring them global without success.

so my question is how to access parameters of a function, outside that function? I'm sure it is something related to my lack to good understanding of variable scope. Thanks for you consideration.
Nightwolf85
Posts: 295
Joined: 05 Feb 2017, 00:03

Re: Timed Traytip

08 Jun 2017, 13:51

What if you declare them as Static

Code: Select all

TrayTip(traytitle :="", traytext := "", traysecs := 3, trayoptions := "") {
	Static title, text, secs, options
	
	title := traytitle
	text := traytext
	secs := traysecs
	options := trayoptions
	
  SetTimer, RemoveTrayTip, % (secs * -1000)
  SetTimer, RefreshTrayTip, 1000

  RefreshTrayTip:
  TrayTip, %title%, %text%, %secs%, %options%
  return
   
  RemoveTrayTip:
  SetTimer, RefreshTrayTip, Off
  TrayTip
  
return
}
I'm not sure if its necessary to use other variables, and I didn't test, just a thought.
c4p
Posts: 17
Joined: 18 Jan 2017, 18:38

Re: Timed Traytip

08 Jun 2017, 14:23

no go on statics
BTW, always disliked timers forcing subroutines instead of functions with arguments.
c4p
Posts: 17
Joined: 18 Jan 2017, 18:38

Re: Timed Traytip

08 Jun 2017, 14:56

took another approach which works but the flicker is unacceptable, and even if my first attempt made to work, it would flicker too.

Code: Select all

TrayTip(traytitle :="", traytext := "", traysecs := 3, trayoptions := "") { ;------------------------------------------------------------------------------
    Loop % traysecs
    {
        TrayTip, %traytitle%, %traytext%, %traysecs%, %trayoptions%
        sleep,  1000
    }
    TrayTip
return
}

Return to “Ask For Help”

Who is online

Users browsing this forum: anaxio, Bing [Bot], inseption86, Jovannb, SamSegal97, tmplinshi and 227 guests