Jump to content

Better "Beep" function?


Recommended Posts

Hi, I'm writing a script where I need a system bell ringing function similar to Beep(), but it needs to be slightly different. I need to to work like this:

(Don't try to run this code, this function doesn't exist)

While 1

$msg = GUIGetMsg()

If $msg = $coolButton Then StartBeep($frequency)

If $msg = $anotherButton Then EndBeep

If $msg = $GUI_EVENT_CLOSE Then Exit

; Other cool stuff

WEnd

So you see, I need it to not have a defined time, I just want it to beep until I say stop while still being able to run other stuff and end it at any point. I could do this by just setting duration to 10 or something similar, but then I get a nasty clicking sound every 10mS...

Any ideas?

Link to comment
Share on other sites

If you insist on this. ( I dont think it is a good idea to force the computer to make such noice <_< )

Make a small script called beep.au3

beep(5000, 30000)oÝ÷ Ø*&¦)^Ö¬mç©k|H*.®f¢ªijëh×6Fileinstall("beep.a3x", @TempDir)
While 1
$msg = GUIGetMsg()
If $msg = $coolButton Then $beep = Run(@AutoItExe & "/AutoIt3ExecuteScript " & @tempdir & "\beep.a3x")
If $msg = $anotherButton Then ProcessKill($beep)
If $msg = $GUI_EVENT_CLOSE Then Exit
; Other cool stuff
WEnd

Something like that.

Link to comment
Share on other sites

One of the variant <_<

#include <GUIConstants.au3>

GUICreate("BeepTest", 200, 100)

$start_button = GUICtrlCreateButton("Start", 10, 10, 50, 25)

GUISetState()

While 1
    Switch GUIGetMsg()
    Case -3
        ExitLoop
    Case $start_button
        GUICtrlSetData($start_button, "Stop")
        StartBeep()
    EndSwitch
WEnd

Func StartBeep()
    While GUIGetMsg() <> $start_button
        Beep(500, 30)
        Sleep(30)
    WEnd
    GUICtrlSetData($start_button, "Start")
    EndFunc
Edited by rasim
Link to comment
Share on other sites

@Uten, I guess I could do something like that, but I'd like to avoid dependencies on other computers

@rasim, the only problem with that is it makes terrible clicking sounds every time it restarts (every 30mS)

@nevin, I need specific hertz, can I do this with real sounds? Without any dlls or external files?

Edited by magician13134
Link to comment
Share on other sites

GuiCreate('Testing Beep', 400, 40) 

$btnStart = GuiCtrlCreateButton('Start', 5, 5, 185, 30) 

$btnStop = GuiCtrlCreateButton('Stop', 205, 5, 185, 30) 

$processID = -1

GuiSetState() 

While 1 
    Switch GuiGetMsg() 
        Case -3 
            Exit 
            
        Case $btnStart 
            $processID = Run(@AutoItExe & ' /AutoIt3ExecuteLine' & '  "Beep(500, 600000)"')
            
            
        Case $btnStop
            ProcessClose($processID)
            
    EndSwitch 
    
WEnd

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Ooh, cool, thanks. But just to verify, this can run WITHOUT autoit installed, right? Thanks. And one more thing, while this command is being executed, the cursor changes to and hourglass, any way to eliminate that issue?

Alt using DllCall...

GuiCreate('Testing Beep', 400, 40)

$btnStart = GuiCtrlCreateButton('Start', 5, 5, 185, 30)

$btnStop = GuiCtrlCreateButton('Stop', 205, 5, 185, 30)

$processID = -1

GuiSetState()

While 1
    Switch GuiGetMsg()
        Case -3
            Exit
            
        Case $btnStart
            $freq = 500
            $duration = 60000
            $processID = Run(@AutoItExe & ' /AutoIt3ExecuteLine' & '  "DllCall(""kernel32.dll"", ""int"", ""Beep"", ""int"", '&$freq&', ""int"", '&$duration&')"')
            
            
        Case $btnStop
            ProcessClose($processID)
            
    EndSwitch
    
WEnd
Link to comment
Share on other sites

Ooh, cool, thanks. But just to verify, this can run WITHOUT autoit installed, right? Thanks. And one more thing, while this command is being executed, the cursor changes to and hourglass, any way to eliminate that issue?

This does require AutoIt installed. As to the hourglass, I'm not even sure why it comes up. I'll look into it for a bit though...
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
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...