Newscritpz Posted June 3, 2013 Share Posted June 3, 2013 I wrote a timer which is activated by an hotkey and when it reaches 10 second it will play a sound. The problem is that if I press "x" times the hotkey then the timer will play the sound "x" times. I cannot find a way to reset the timer using the hotkey, without playing the sounds many times. For example: - I press "f" to let it start - Timer is started, and I want to reset it when reaches 5 seconds so I press again "f" - Then, I press "f" after 3 seconds - I wait the end of the script, but instead of playing the sound only once, it will be played three times. I tried to put HotKeySet("{f}" ) inside the count function to fix it but doing so, the timer will not reset. HotKeySet("{f}", "Count") Idle() Func Idle() While True ToolTip("Seconds Count = " & "OFF", 0, 0, "", 1) Sleep(100) WEnd EndFunc Func Count() $Sec = 10 Local $Count = 0, $begin = TimerInit() While $Sec > $Count $dif = TimerDiff($begin) $dif2 = StringLeft($dif, StringInStr($dif, ".") -1) $Count = int($dif/1000) ToolTip("Seconds Count = " & $Count, 0, 0, "", 1) Sleep(20) WEnd SoundPlay(@WindowsDir & "\Media\Ding.wav", 1) Return EndFunc Link to comment Share on other sites More sharing options...
Markos Posted June 3, 2013 Share Posted June 3, 2013 Basically what you want to do is to register a one-time timer on your hotkey press, which after the period plays the sound. When the timer is running, and hotkey is pressed again, you want to unregister the previous timer and register a new one. Link to comment Share on other sites More sharing options...
JotaPx Posted June 3, 2013 Share Posted June 3, 2013 HotKeySet("{f}", "Count") Idle() Func Idle() While True ToolTip("Seconds Count = " & "OFF", 0, 0, "", 1) Sleep(100) HotKeySet("{f}", "Count") WEnd EndFunc Func Count() HotKeySet("{f}") $Sec = 3 Local $Count = 0, $begin = TimerInit() While $Sec > $Count $dif = TimerDiff($begin) $dif2 = StringLeft($dif, StringInStr($dif, ".") -1) $Count = int($dif/1000) ToolTip("Seconds Count = " & $Count, 0, 0, "", 1) Sleep(20) WEnd SoundPlay(@WindowsDir & "\Media\Ding.wav", 1) Return EndFunc this works for me Link to comment Share on other sites More sharing options...
Newscritpz Posted June 4, 2013 Author Share Posted June 4, 2013 this works for me Yes I have tried this way too, but if I press the hotkey the timer won't reset while counting. Link to comment Share on other sites More sharing options...
Newscritpz Posted June 4, 2013 Author Share Posted June 4, 2013 (edited) Basically what you want to do is to register a one-time timer on your hotkey press, which after the period plays the sound. When the timer is running, and hotkey is pressed again, you want to unregister the previous timer and register a new one. Yes I've tried also this but doesnt work: HotKeySet("{f}") Send("{f}") HotKeySet("{f}", "Count") When the timer reach the end It will play the sound "x" times, where "x" = n° of "f" hotkey pressed HotKeySet("{f}", "Count") Idle() Func Idle() While True ToolTip("Seconds Count = " & "OFF", 0, 0, "", 1) Sleep(100) WEnd EndFunc Func Count() HotKeySet("{f}") Send("{f}") HotKeySet("{f}", "Count") $Sec = 10 Local $Count = 0, $begin = TimerInit() While $Sec > $Count $dif = TimerDiff($begin) $dif2 = StringLeft($dif, StringInStr($dif, ".") -1) $Count = int($dif/1000) ToolTip("Seconds Count = " & $Count, 0, 0, "", 1) Sleep(20) WEnd SoundPlay(@WindowsDir & "\Media\Ding.wav", 1) Return EndFunc Edited June 4, 2013 by Newscritpz Link to comment Share on other sites More sharing options...
Newscritpz Posted June 6, 2013 Author Share Posted June 6, 2013 up Link to comment Share on other sites More sharing options...
FireFox Posted June 6, 2013 Share Posted June 6, 2013 (edited) Hi,Take a look at my "Advanced HotKeySet" link in my signature (under My Snippets), and play with the flags.You should get what you expect Edit: Note that the example is a little bit "complicated", you can strip the half of the code if you don't need a GUI/disable hotkeys outside your GUI.Br, FireFox. Edited June 6, 2013 by FireFox Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now