Jump to content

Do Beep until a key is pressed


Go to solution Solved by Dan_555,

Recommended Posts

Hi guys can someone guide me it seems that my code runs in a loop and does not work correctly.

#include <Misc.au3>
#include <MsgBoxConstants.au3>
Local $hDLL = DllOpen("user32.dll")

While 1
   ;_IsPressed("51", $hDLL) equals Letter Q
   Do
    Beep(500, 1000)
    Sleep(2000)
   Until _IsPressed =_IsPressed("51", $hDLL)


WEnd

DllClose($hDLL)

 

Link to comment
Share on other sites

  • Solution

Maybe because you have 2 nested loops: While 1 ... Do .. Until ... Wend

When you exit out of the do loop, it loops forever again in the while loop.

Here is a solution:

#include <Misc.au3>

Local $hDLL = DllOpen("user32.dll")
$hTime = TimerInit()

Do
    If TimerDiff($hTime) > 2000 Then
        Beep(500, 1000)
        $hTime = TimerInit()
    EndIf

Until _IsPressed("51", $hDLL)

DllClose($hDLL)

 

Some of my script sourcecode

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...