shaqan Posted September 3, 2011 Share Posted September 3, 2011 HiI am working on alarm clock program. It is working fairly nicely, except for one GUI button which I wanted to use for canceling the alarm sound. It sort of works and sort of.. not - I have to press on GUI button multiple times before it does what it should do.. Sometimes have to push it just few times, sometimes a dozen..relevant portion of the codeDo SoundPlay("d:\WINDOWS\Media\ringin.wav",1) Until GUIGetMsg() <> $Peata_Aratus_Nupp$Peata_Aratus_Nupp is the GUI button and Until GUIGetMsg() <> $Peata_Aratus_Nupp is the expression giving me the head aches.. I tried While GUIGetMsg() <> $Peata_Aratus_Nupp loop instead of Do..Until. Had same problem - sort of worked but very sluggishly I looked into at GuiGetMsg topic in AutoIT3 helpfile but could not find much help.. In fact I am not sure if I should have used GuiGetMsg the way I did.. In forum I found one thread which had sample (also covering trouble with GUI button) using expression likeWhile GuiGetMsg <> -3but I could not figure out from where this "-3" was derived fromI would appreciate some advice:) Link to comment Share on other sites More sharing options...
guinness Posted September 3, 2011 Share Posted September 3, 2011 (edited) -3 is $GUI_EVENT_CLOSE or the red cross in the top of the GUI. Why not use something like this... While 1 SoundPlay("Ring", 1) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; You will need GUIConstantsEx.au3. Exit ; Or ExitLoop to exit the while loop. EndSwitch WEnd Edited September 4, 2011 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
shaqan Posted September 3, 2011 Author Share Posted September 3, 2011 (edited) Ok thanks, for explaining the "-3" thing EDIT: Gave your advice a try and It seems to work better. Not 100% of button presses work but roughly 2 out of 3.. Good enough for me so Thank You:) Edited September 3, 2011 by shaqan Link to comment Share on other sites More sharing options...
monoscout999 Posted September 4, 2011 Share Posted September 4, 2011 (edited) did you have a sleep inside the GuiGetMsg() Loop? you do not need it Edited September 4, 2011 by monoscout999 Link to comment Share on other sites More sharing options...
shaqan Posted September 4, 2011 Author Share Posted September 4, 2011 initially yes.. but before I made this thread I replaced it with Soundplay("/blabla/file.wav",1) though.. something still lagged the GUI Link to comment Share on other sites More sharing options...
monoscout999 Posted September 4, 2011 Share Posted September 4, 2011 So this is the only thing that is in the loop? Do SoundPlay("d:\WINDOWS\Media\ringin.wav",1) Until GUIGetMsg() = - 3 The second parameter in the SoundPlay make stops the script until the sound is over, read the help file about it. Link to comment Share on other sites More sharing options...
guinness Posted September 4, 2011 Share Posted September 4, 2011 Change Wait to 0! SoundPlay ( "filename" [, wait] ) UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
shaqan Posted September 4, 2011 Author Share Posted September 4, 2011 when I change it to "0", alarm sound changes to machinegun like very rapid ratatatatatata..Soundplay gets initiated over and over before It completes playing the sound from previous cycle.. I could "fix" it by adding Sleep() but its pointless.. So its like running in circles... and I made error I posted Until GUIGetMsg() <> $Peata_Aratus_Nupp where it actually appears to work as Until GUIGetMsg() = $Peata_Aratus_Nupp Link to comment Share on other sites More sharing options...
ahmet Posted September 4, 2011 Share Posted September 4, 2011 You can use SoundPlay("") to stop currently playing sound. Link to comment Share on other sites More sharing options...
monoscout999 Posted September 4, 2011 Share Posted September 4, 2011 You can use SoundPlay("") to stop currently playing sound. That doesn´t gonna make any difference... maybe if you play the sound as AdlibFunction to abvoid hung the main loop. A question, why do you want to play a sound in a loop? is important te me know the context because i can give a more adecuate out-of-the-box answer. Link to comment Share on other sites More sharing options...
shaqan Posted September 4, 2011 Author Share Posted September 4, 2011 (edited) A question, why do you want to play a sound in a loop? is important te me know the context because i can give a more adecuate out-of-the-box answer. Eventually I want to give end-user the option of choosing between different alarm sounds.. Very small wav/mp3-s running in loop save quite a lot of disk space.. Also, the alarm is supposed to run full minute, before it stops (unless aborted manually by button I am at the moment having trouble with) It´s my fun project for the most part but 3-4 of my colleagues probably will also be using it (at least it would be more convenient than using Windows Task Scheduler for starting Media Player as substitute alarm clock[notebook computer beside bed]).. We have shifts with interval of 6h inbetween.. Waking up at 1AM after having 2 shifts during previous 24h (border police, before you ask about the work lol) can be trifle hard sometimes.. so additional backup alarm "clock" besides cell phone is good thing.. "Alarm" programs I have looked in Internet are usually Shareware and I dont care much about pirating and/or just way too overly functional/complicated for computer illiterates.. Edited September 4, 2011 by shaqan Link to comment Share on other sites More sharing options...
GEOSoft Posted September 4, 2011 Share Posted September 4, 2011 You have your SoundPlay() set to block further script action with the 1 flag. Just use the default SoundPlay("somefile.wav") George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
shaqan Posted September 4, 2011 Author Share Posted September 4, 2011 (edited) You have your SoundPlay() set to block further script action with the 1 flag. Just use the defaultSoundPlay("somefile.wav") Default and "0" appear to be identical.. test running made no difference either when I change it to "0", alarm sound changes to machinegun like very rapid ratatatatatata..Soundplay gets initiated over and over before It completes playing the sound from previous cycle.. I could "fix" it by adding Sleep() but its pointless.. So its like running in circles... anyway thanks for trying to help.. It sort of works anyway and "cancel alarm" button not working properly could actually be positive item.. harder to just punch it off and continue sleeping "just 5 more minutes".. Edited September 4, 2011 by shaqan Link to comment Share on other sites More sharing options...
monoscout999 Posted September 4, 2011 Share Posted September 4, 2011 (edited) The problem is that the loop is too short, so the sounds go over and over and over... maybe an AdlibFuncion this way. GuiCreate("test") GuiSetState() AdlibRegister("playalarm",1000) ; every second... $Timer = TimerInit() Do If TimerDiff($Timer) = 1000*60 then AdlibUnregister("playalarm") ; In one minute it will stop of doing that function. until GuiGetMsg() = -3 Func playalarm() ; ...will do this function. SoundPlay("d:\WINDOWS\Media\ringin.wav",0) EndFunc Edited September 4, 2011 by monoscout999 Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted September 5, 2011 Share Posted September 5, 2011 when I change it to "0", alarm sound changes to machinegun like very rapid ratatatatatata..Soundplay gets initiated over and over before It completes playing the sound from previous cycle.. So check if the file have finished playing before playing it again. See "Sound Management" in helpfile. Or use something like the BASS UDF that does the looping for you. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
shaqan Posted September 5, 2011 Author Share Posted September 5, 2011 Tried AdLibRegister.. Worked but ran into odd problem.. one function enabling/disabling GUI elements, using "GUICtrlSetState" stopped functioning (had suddenly no visible effect on GUI).. Ill poke around with it but in some other script, its interesting Sound Management & _SoundPlay finally helped out. Now it works like I wanted. Tnx Link to comment Share on other sites More sharing options...
huldu Posted September 6, 2011 Share Posted September 6, 2011 Loops and a GUI don't really work that great together. I am sure there are ways to make the button far more responsive during a loop. Anyway... my approach with loops and GUI is using hotkeys, it works but the buttons in the GUI aren't reliable. Hotkeys always works for me. "I'm paper, rock is fine, nerf scissors!!!" Link to comment Share on other sites More sharing options...
monoscout999 Posted September 6, 2011 Share Posted September 6, 2011 (edited) Loops and a GUI don't really work that great together. I am sure there are ways to make the button far more responsive during a loop. Anyway... my approach with loops and GUI is using hotkeys, it works but the buttons in the GUI aren't reliable. Hotkeys always works for me.To me works fine Show me a problematic loop to see where is the problem. Remember that you should not use Blocking functions in a GuiGetMsg() Loop Edited September 6, 2011 by monoscout999 Link to comment Share on other sites More sharing options...
huldu Posted September 6, 2011 Share Posted September 6, 2011 (edited) Just found out about GUIRegisterMsg. That would probably work wonders. I usually encounter problems if you have a GUI with buttons and using loops containing sleep. If you have a "start" button along with a "stop" button, by clicking the "start" button a loop begin in this loop there is also a sleep, say 500ms for this example. Now if you were to click the "stop" button this won't work if the script is currently in the sleep. In many cases the entire application will be frozen/non-responsive. If you use hotkeys you can exit the loop but you'd have to use the keyboard which is the problem. Using the GUIRegisterMsg it seems possible through some work to actually stop the loop using the GUI buttons, in this case "stop". I found this code a few pages back on this forum, i'll post it again since i don't have the url. Looks really great. expandcollapse popup#include #include ; Set a HotKey HotKeySet("x", "_Interrupt_HotKey") ; Declare a flag $fInterrupt = 0 Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $hButton_1 = GUICtrlCreateButton("Func One", 10, 10, 80, 30) GUICtrlSetOnEvent($hButton_1, "_Func_1") $hButton_2 = GUICtrlCreateButton("Func Two", 10, 50, 80, 30) GUICtrlSetOnEvent($hButton_2, "_Func_2") ; Create a dummy control for the Accelerator to action $hAccelInterupt = GUICtrlCreateDummy() GUICtrlSetOnEvent($hAccelInterupt, "_Interrupt_Accel") ; Set an Accelerator key to action the dummy control Dim $AccelKeys[1][2]=[ ["z", $hAccelInterupt] ] GUISetAccelerators($AccelKeys) GUISetState() ; Intercept Windows command messages with out own handler GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Sleep(10) WEnd Func _Func_1() ; Make sure the flag is cleared $fInterrupt = 0 For $i = 1 To 20 ConsoleWrite("-Func 1 Running" & @CRLF) ; Look for the flag If $fInterrupt 0 Then ; The flag was set Switch $fInterrupt Case 1 ConsoleWrite("!Func 1 interrrupted by Func 2" & @CRLF) Case 2 ConsoleWrite("!Func 1 interrrupted by HotKey" & @CRLF) Case 3 ConsoleWrite("!Func 1 interrrupted by Accelerator" & @CRLF) EndSwitch Return EndIf Sleep(100) Next ConsoleWrite(">Func 1 Ended" & @CRLF) EndFunc Func _Func_2() For $i = 1 To 3 ConsoleWrite("+Func 2 Running" & @CRLF) Sleep(100) Next ConsoleWrite(">Func 2 Ended" & @CRLF) EndFunc Func _Exit() Exit EndFunc Func _Interrupt_HotKey() ; The HotKey was pressed so set the flag $fInterrupt = 2 EndFunc Func _Interrupt_Accel() ; This is an empty function for the dummy control linked to the Accelerator key EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ; The Func 2 button was pressed so set the flag If BitAND($wParam, 0x0000FFFF) = $hButton_2 Then $fInterrupt = 1 ; The dummy control was actioned by the Accelerator key so set the flag If BitAND($wParam, 0x0000FFFF) = $hAccelInterupt Then $fInterrupt = 3 Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND Weird formatting when trying to modify the post... should be proper now. Edited September 6, 2011 by huldu "I'm paper, rock is fine, nerf scissors!!!" Link to comment Share on other sites More sharing options...
monoscout999 Posted September 7, 2011 Share Posted September 7, 2011 You should not use Sleep() in the same loop that contains a GuiGetMsg() call read the help file about it. 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