TheOnlyOne Posted July 15, 2016 Posted July 15, 2016 (edited) So currently I have some code waiting for a status to change(there is different indicators to check if this status has changed) Func oneRow($count) $globaltimer = _Timer_SetTimer($gui, 60000*10, "reset") $errTimer = TimerInit() While (1) If PixelGetColor(1117, 326) = 0xC6C6C6 Then ExitLoop (1) Sleep(500) MouseClick("right") Sleep(600) If PixelGetColor(1117, 326) = 0xC6C6C6 Then ExitLoop (1) If TimerDiff($errTimer) > 5000 Then If PixelGetColor(1100, 310) = 0x707070 Or PixelGetColor(901, 305) = 0xE0E0E0 Or PixelGetColor(1043, 383) = 0xC6C6C6 Then Sleep(100) Send("{esc}") Sleep(1000) EndIf EndIf WEnd .... EndFunc ;==>oneRow The two timers is for error checking. This works just fine the problem comes when I go into the while 1 loop, my hotkeys at the top of the program seems to stop working, for an example HotKeySet("{f1}", "stop") Func stop() Exit EndFunc ;==>stop Does not work at all after the while loop. The globaltimer is never called even though i tried setting the delay all the way down to 3 seconds. So I thought that maybe one of the function I use is blocking so the timer would never be called/the hotkey wouldn't work? if i make an delay just before the while loop the hotkey works just fine. Oh and the errTimer is supossed to not reset after 5 seconds but should keep making the check it does if five seconds have passed Edited July 15, 2016 by TheOnlyOne words are hard
SadBunny Posted July 15, 2016 Posted July 15, 2016 Can't reproduce, your code is not testable for anyone else, the rest of your code and/or the application that you're trying to work with and/or pretty much anything else may throw sand in the machine. I tried to write a small reproducer that uses both types of timers at the same time as well and a hotkey, works fine for me: #include <Timers.au3> HotKeySet("x", "exiter") doThing() Exit Func doThing() $globaltimer = _Timer_SetTimer(-1, 10000, "doBeep") $beepTimer = TimerInit() While (1) If TimerDiff($beepTimer) > 6000 and TimerDiff($beepTimer) < 8000 Then Beep(2000, 300) EndIf WEnd EndFunc ;==>doThing Func doBeep() Beep(1000, 300) Sleep(100) EndFunc ;==>doBeep Func exiter() Exit EndFunc ;==>exiter Can you try and reproduce your issue with a standalone reproducer script? TheOnlyOne 1 Roses are FF0000, violets are 0000FF... All my base are belong to you.
AutoBert Posted July 15, 2016 Posted July 15, 2016 Your script snipets should work, if the scipt is correctly completed, so post whole runable (reproducer) sdcript, showing your issue. But maybe another skript capures the F1-key? Quote If two AutoIt scripts set the same hotkeys, you should avoid running those scripts simultaneously as the second script cannot capture the hotkey unless the first script terminates or unregisters the key prior to the second script setting the hotkey.
TheOnlyOne Posted July 15, 2016 Author Posted July 15, 2016 (edited) Hmm not sure I can do that, I see that your example is working for me too. I have this code calling my function $return = 0 For $i = 0 To 5 If $pause = True Then pause() EndIf MsgBox(0,"","before one row") $return = oneRow($i) MsgBox(0,"",$return) If $return = 232 Then Return 232 Sleep($waitDelay) Next the msgboxes is something i inserted for debugging purposes. I also tried to add MsgBox(0,"","first") to the top of the oneRow function. So when i run the code it runs as expected the first time, shows "before one row" messagebox and afterwards the "first" msgbox. Then after 5 seconds it actually shows the "before one row" msgbox again so it must have passed one of my pixelgetcolor calls(even though the status isnt correct yet). So i tried adding this to the if block that passes If PixelGetColor(1100, 310) = 0x707070 Or PixelGetColor(901, 305) = 0xE0E0E0 Or PixelGetColor(1043, 383) = 0xC6C6C6 Then MsgBox(0,"","sucess " & @crlf & hex(PixelGetColor(1100, 310)) & @crlf & hex(PixelGetColor(901, 305)) & @crlf & hex(PixelGetColor(1043, 383))) Sleep(100) Send("{esc}") Sleep(1000) EndIf But the msgbox is never shown. If i add an empty msgbox it is shown. I tried without the hex call but with the same result, is the pixegetcolor function returning errors maybe, i have never seen that before? Another weird thing is after it shows the "before one row" msgbox the second time it doesnt show the next msgbox at the top of oneRow function ? As you said my code is properly to messy atm. I would have a hard time making a reproducable example which is not very good.. Edited July 15, 2016 by TheOnlyOne removed duplicate code tags
SadBunny Posted July 15, 2016 Posted July 15, 2016 I'm not saying whether or not your code is messy, and even messy code should still work if it is actually correct (just harder to work with ). If you want to know how far your code gets during execution, there are a few shortcuts you could take to get some information, such as enabling the TrayIconDebug option or using Tools -> Trace: add trace lines in Scite. You can always add your own ConsoleWrite commands to show more debug information, such as results, errors and extended error information returned from function calls. (Much more useful than MsgBox'es IMHO as they don't require interaction, don't overlap any gui etc..) I personally cannot see anything intrinsically wrong with this code (maybe someone else can?), but without clear information on when what happens exactly, it's blindfolded troubleshooting, at least to me. But that's what reproducers are for. The thing with reproducers is that if you feel like you would have a hard time making one, it's probably a sign that you have to rethink your solution to begin with, otherwise it's just trial-and-error to find a working band-aid... TheOnlyOne 1 Roses are FF0000, violets are 0000FF... All my base are belong to you.
water Posted July 15, 2016 Posted July 15, 2016 I'm not sure but I think "Sleep" is a blocking function. The help file tells us: "If the current function is a "blocking" function, then the key-presses are buffered and execute as soon as the blocking function completes." My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
SadBunny Posted July 15, 2016 Posted July 15, 2016 (edited) HotKeySet functionality remains active and also works immediately during a sleep. /edit Tested with: HotKeySet("x", "quitter") Beep(1000, 200) sleep(20000) Func quitter() Beep(1500, 200) Exit EndFunc ;==>quitter Edited July 15, 2016 by SadBunny Roses are FF0000, violets are 0000FF... All my base are belong to you.
TheOnlyOne Posted July 15, 2016 Author Posted July 15, 2016 (edited) Yea I might have to rethink the solution.. just annoys me because I feel like it should work. I just tried to add a tooltip to the while loop in oneRow() with the timerdiff inside. So the hotkey apperently works until 30-40 seconds have passed ?? there is no other code being executed other than the code inside the loop .. Edited July 15, 2016 by TheOnlyOne
Developers Jos Posted July 15, 2016 Developers Posted July 15, 2016 Show me a simple reproducer of your script which actually works and we can check as to why you are seeing this. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
TheOnlyOne Posted July 15, 2016 Author Posted July 15, 2016 (edited) Okay I might have found the problem with why the hotkeyset didn't work. I took another look at your first example @SadBunny and saw you used -1 for the hwnd. I thought you had to give it a GUI reference so i had created one like this, with the timer referencing it as shown earlier: $gui = GUICreate("", 0, 0) $globaltimer = _Timer_SetTimer($gui, Random(6000 * 2, 6000 * 5, 1), "reset") I tried changing $gui to -1 and now the hotkey works even after 60+ seconds why is that? The function reset does not seem to be called though ? Tried chaning it to 10 seconds instead of a random generated number but with the same result? Func reset() _Timer_KillTimer($gui, $globaltimer) MsgBox(0, "", "in reset") ... EndFunc ;==>reset the callback function never seems to be called in your example nether Edited July 15, 2016 by TheOnlyOne
SadBunny Posted July 15, 2016 Posted July 15, 2016 True, and I didn't want/need it to, I just wanted it to exist. Now that you mention it, the result of that _Timer_SetTimer returns 0 so the timer call fails and my test is faulty. That means that in your new case, the timer probably isn't created either and now your hotkey now remains working. So the problem still looks to be with that combination, or some contingency combined with that combination. Finding out which one of those two is the case is a matter of elimination Either start from scratch with that combination and see if you can reproduce, or snip away every other contingency until you arrive at the last contingency that determines whether this problem occurs or not, and you can write a reproducer (and/or find your error ). TheOnlyOne 1 Roses are FF0000, violets are 0000FF... All my base are belong to you.
SadBunny Posted July 15, 2016 Posted July 15, 2016 So here the timer actually works Maybe this is better to play around with? #include <Timers.au3> HotKeySet("x", "exiter") Global $gui = GUICreate("hello", 300, 300, 100, 100) ;~ GUISetState(@SW_SHOW, $gui) doThing() Exit Func doThing() Local $globaltimer = _Timer_SetTimer($gui, 6000, "doTimerFunction") ConsoleWrite("Timer id: " & $globaltimer & @CRLF) $beepTimer = TimerInit() While (1) If TimerDiff($beepTimer) > 3000 And TimerDiff($beepTimer) < 4000 Then Beep(1500, 100) EndIf WEnd Sleep(10000) EndFunc ;==>doThing Func doTimerFunction($hWnd, $iMsg, $iIDtimer, $iTime) Beep(1000, 300) EndFunc ;==>doBeep Func exiter() Exit EndFunc ;==>exiter TheOnlyOne 1 Roses are FF0000, violets are 0000FF... All my base are belong to you.
TheOnlyOne Posted July 15, 2016 Author Posted July 15, 2016 Oh god i feel so stupid .. my reset function didn't have any parameters.. Well thanks for your help, would properly been stuck with this for atleast a few hours more without it.
SadBunny Posted July 15, 2016 Posted July 15, 2016 See, this is why reproducers are so important 9 out of 10 times (if not more) even the process of trying to come up with a reproducer from scratch, or stripping your code down until the problem disappears and then looking at the last thing you stripped, shows the actual problem. Well, glad I could help TheOnlyOne 1 Roses are FF0000, violets are 0000FF... All my base are belong to you.
SadBunny Posted July 15, 2016 Posted July 15, 2016 P.S. Small note: where you write "properly" (also earlier in this thread) you meant "probably". I'm not a grammar Nazi or anything, but confusing those two can lead to actual confusion TheOnlyOne 1 Roses are FF0000, violets are 0000FF... All my base are belong to you.
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