whizter Posted November 25, 2010 Posted November 25, 2010 hi I need some help. I'm trying to get this to work, but everything seems to fail. This is what I have: 1) a button ("Start (F8)") 2) a hotkey ("{F8}") 3) Opt("GUIOnEventMode", 1) I can't use a msg loop cause of blocking functions! HotKeySet("{F8}", "togglePause") $btnStart = GUICtrlCreateButton("Start (F8)", 217, 101, 135, 44, $WS_GROUP) GUICtrlSetFont(-1, 14, 800, 0, "Verdana") GUICtrlSetOnEvent(-1, "togglePause") Func togglePause() $paused = Not $paused If ($paused) Then GUICtrlSetData($btnStart, "Start (F8)") EndIf While $paused Sleep(50) WEnd GUICtrlSetData($btnStart, "Stop (F8)") EndFunc If I click Start/Stop twice then every button stops responding, I can't close the form etc. Using the Hotkey I have no problems. I don't understand why this isn't working, is there a way to get this working without a msgloop?
whizter Posted November 25, 2010 Author Posted November 25, 2010 (edited) hotkeys are working fine. but it seems like every event is ignored as long as I'm inside the function that the last event called. Is there a solution to this problem? Edited November 25, 2010 by whizter
whizter Posted November 25, 2010 Author Posted November 25, 2010 well, I didn't solve the problem itself but I think this is an acceptable solution, it can be started using the button but it can only be stopped using the hotkey, which is ok for me: Func togglePause() $paused = Not $paused If ($paused) Then GUICtrlSetData($btnStart, "Start: [F8]") GUICtrlSetState ($btnStart,$GUI_ENABLE) EndIf While $paused Sleep(50) WEnd GUICtrlSetData($btnStart, "Stop: [F8]") GUICtrlSetState ($btnStart,$GUI_DISABLE) EndFunc ;==>togglePause
SadBunny Posted November 25, 2010 Posted November 25, 2010 Intriguing. I found the exact same thing trying to reproduce: OnEvent function calling seems to not support recursion; hotkeys do. I don't know if it is intended OnEvent behaviour... You can ofcourse put your pauseloop outside of the function itself so that it exits the togglePause() and loops elsewhere if $paused==True, but judging your post I'd say that you already thought of that but that your script doesn't have, or isn't always looping through, one main loop? Roses are FF0000, violets are 0000FF... All my base are belong to you.
whizter Posted November 25, 2010 Author Posted November 25, 2010 (edited) Intriguing. I found the exact same thing trying to reproduce: OnEvent function calling seems to not support recursion; hotkeys do. I don't know if it is intended OnEvent behaviour... You can ofcourse put your pauseloop outside of the function itself so that it exits the togglePause() and loops elsewhere if $paused==True, but judging your post I'd say that you already thought of that but that your script doesn't have, or isn't always looping through, one main loop? Yes I already thought of that. I have a main loop, but I can't check there because various functions are called from there that take some time to compute (and I want my start/stop button to react immediately), and in that timespan my button wouldn't work then. It would be like using a msgloop. That's the problem, and now I think there's no real solution to it.EDIT: I got an idea now, what about switching GUIOnEventMode on the fly and start a msgloop instead of my waiting loop? Well, I will test this tomorrow, going to bed now. Edited November 25, 2010 by whizter
Zedna Posted November 25, 2010 Posted November 25, 2010 (edited) I know you don't want to use Msg modebut look at my topic "GUISetAccelerators() as replace for HotKeySet() - how to use it for my own functions (without associated control)" Edited November 25, 2010 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
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