Sign in to follow this  
Followers 0
whizter

Hotkeys and Buttons

6 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by whizter

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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? :graduated:


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

#5 ·  Posted (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? :graduated:

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 by whizter

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I know you don't want to use Msg mode

but look at my topic

"GUISetAccelerators() as replace for HotKeySet()

- how to use it for my own functions (without associated control)"

Edited by Zedna

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  
Followers 0