Jump to content
Sign in to follow this  
magician13134

Better "Beep" function?

Recommended Posts

magician13134

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?

Share this post


Link to post
Share on other sites
Achilles

Try making it beep for a super long time when you press start and then when you want to stop make it beep for 10 ms or maybe 0.. The new beep should cancel out the old one and end quickly.. I don't have time to try but it might work.


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
Uten

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.

Share this post


Link to post
Share on other sites
rasim

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

Share this post


Link to post
Share on other sites
Nevin

Don't forget you could just play real sounds.

Share this post


Link to post
Share on other sites
magician13134

@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

Share this post


Link to post
Share on other sites
Achilles

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]

Share this post


Link to post
Share on other sites
magician13134

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?

Share this post


Link to post
Share on other sites
BrettF

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

Share this post


Link to post
Share on other sites
Achilles

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]

Share this post


Link to post
Share on other sites
Achilles

It may just be my computer.

No... It does that on mine too... I tried GuiSetCursor but that wasn't working right. I'll be there's a .dll you can call but I'm no expert on those..

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

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  

×