IAMK Posted April 27, 2018 Share Posted April 27, 2018 (edited) This is a fairly simply script, but the feel of it is terrible. Currently, the script has an infinite file loop with a 1-second sleep. Each time, it will check if the picture on my GUI has been clicked or not. However, this is not good, especially if clicked multiple times, as I need the if statement to happen ASAP, not after a possible 1-second sleep. $pic = GUICtrlCreatePic("image.jpg", 0, 0, 100, 35) ;Just for reference for below. While(1) $msg = GUIGetMsg() If $msg = $pic Then Send("Hello") EndIf Sleep(1000) WEnd I can't seem to find a way to use GUI Pic clicks as an event like HotKeySet. E.g. HotKeySet("{DEL}", "endScript") Thank you in advance. Edited April 27, 2018 by IAMK Link to comment Share on other sites More sharing options...
therks Posted April 27, 2018 Share Posted April 27, 2018 (edited) I'm not sure I understand the issue. Just take out the sleep. This is how most GUI scripts work anyway. #include <GUIConstants.au3> $hGUI = GUICreate('GUI') $pic = GUICtrlCreatePic('image.jpg', 0, 0, 100, 35) GUISetState() While 1 Switch GUIGetMsg() Case $pic endScript() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func endScript() Exit ; ? EndFunc Edited April 27, 2018 by therks My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
IAMK Posted April 30, 2018 Author Share Posted April 30, 2018 @therks, That's the same as what I have. The issue with that implementation is if you have a 10-second sleep at the end of the while, the script will wait before checking if the label was pressed. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 30, 2018 Developers Share Posted April 30, 2018 (edited) There should never be a sleep() statement in a close message loop. Jos Edited April 30, 2018 by Jos therks 1 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. Link to comment Share on other sites More sharing options...
IAMK Posted April 30, 2018 Author Share Posted April 30, 2018 @Jos, If there is no sleep, then it will cycle through 100000x really quickly, eating up my CPU/performance. I need this to run alongside other scripts + my company's project (which needs to be performing at normal visual speeds). No lag/stutter should be observed. Also, the label can be pressed more than once, so I'm not just polling until it's pressed then running a script. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 30, 2018 Developers Share Posted April 30, 2018 Nope, the GuiGetMsg() has an build in 10 ms delay and making that more will cause all kinds of issues with capturing the messages from the gui! So removing the sleep() will not cause a close loop without a pause. Jos therks 1 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. Link to comment Share on other sites More sharing options...
IAMK Posted May 1, 2018 Author Share Posted May 1, 2018 @Jos, Even then, I believe it may be an issue in a more complex script. For this simple script, it is fine. My project needs to remain 60fps. It's fine. I guess this can't be done the same way as a hotkey which can be called from anywhere. Thanks. Link to comment Share on other sites More sharing options...
Developers Jos Posted May 1, 2018 Developers Share Posted May 1, 2018 It is a problem when you introduce the sleep() in the close message loop so you need to come up with the logic that it also works for you without intoducing the sleep(), not the other way around! 5 hours ago, IAMK said: My project needs to remain 60fps I have no idea what that means other than you want 60 frames per second for something. I would say try usimg AdlibRegister() for braking out of the regular loop at that interval to perform a Func. 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. Link to comment Share on other sites More sharing options...
IAMK Posted May 1, 2018 Author Share Posted May 1, 2018 (edited) 1 hour ago, Jos said: I have no idea what that means other than you want 60 frames per second for something. My company's projects are animation-based, so the visuals should look normal/smooth while my scripts run. I like the Adlib function, thanks. I will use it for other things Edited May 1, 2018 by IAMK 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