Sign in to follow this  
Followers 0
Newscritpz

Hotkey problem with a simple timer

7 posts in this topic

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

 

Share this post


Link to post
Share on other sites



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.


Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

this works for me

Yes I have tried this way too, but if I press the hotkey the timer won't reset while counting.

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by Newscritpz

Share this post


Link to post
Share on other sites

up :(

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0