Jump to content

Is it possible to reset OnEvent Mode...


dabus
 Share

Recommended Posts

Hi there,

I must admit that I did not use OnEvent mode that much.

I obviously use it in a script that does something to catch events during that time.

Since I thought I might switch everything to OnEvent, I was in the process of changing the whole script, adding new tabs, changing here and there and stumbled about the fact that new events are "ignored" until a function that was triggered by another event is done.

Because I need to keep the OnEvent on the "doing something"-part, I wonder if it would be possible to reset the OnEvent-Mode so that it is free/available for new events...

I tried to switch it off and on again, but that did not work.

Best regards

dabus

Edited by dabus
Link to comment
Share on other sites

Hi there,

I must admit that I did not use OnEvent mode that much.

I obviously use it in a script that does something to catch events during that time.

Since I thought I might switch everything to OnEvent, I was in the process of changing the whole script, adding new tabs, changing here and there and stumbled about the fact that new events are "ignored" until a function that was triggered by another event is done.

Because I need to keep the OnEvent on the "doing something"-part, I wonder if it would be possible to reset the OnEvent-Mode so that it is free/available for new events...

I tried to switch it off and on again, but that did not work.

Best regards

dabus

You should be able to switch onevent mode on and off.

If you only want to allow for one 'interruption' then the usual way round handling an event when you are already handling a previous one is to make your event just set a flag and return. Then in your main idle loop you call the function if the flag is set and reset the flag of course. Then when you are in the function callled from the idle loop you can respond to another event.

You could do that for all events but then you would end up reproducing the messge loop approach.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Could you give an example?

Here's what I mean.

This does not work, since the continue-button does not responde:

AutoItSetOption('GUIOnEventMode', 1)
Global $Keep=1
GUICreate('sample', 200, 100)
$Open=GUICtrlCreateButton('Stop', 10, 10, 100, 20)
GUICtrlSetOnEvent(-1, 'Stop')
$Close=GUICtrlCreateButton('Continue', 10, 50, 100, 20)
GUICtrlSetOnEvent(-1, 'Continue')
GUISetState()

while 1
    Sleep(1000)
    ConsoleWrite($Keep & @CRLF)
WEnd    

Func Stop()
    While $Keep
        Sleep(10)
    WEnd    
EndFunc 

Func Continue()
    $Keep = 0
EndFuncoÝ÷ Ù8b±Ú³
+»­¶¶­ßÛ,Â+)àmëpyéíè.Ê'qêm³ù¨uëºÚ"µÍ]]Ò]Ù]Ü[Û    ÌÎNÑÕRSÛ][[ÙIÌÎNËJBÛØ[   ÌÍÒÙYLBÕRPÜX]J    ÌÎNÜØ[IÌÎNËL
BÌÍÓÜ[QÕRPÝÜX]P]Û   ÌÎNÔÝÜ ÌÎNËLLL
BÕRPÝÙ]Û][
LK  ÌÎNÔÝÜ ÌÎNÊBÌÍÐÛÜÙOQÕRPÝÜX]P]Û    ÌÎNÐÛÛ[YIÌÎNËL
LL
BÕRPÝÙ]Û][
LK  ÌÎNÐÛÛ[YIÌÎNÊBÕRTÙ]Ý]J
BÚ[HBTÛY
L
BPÛÛÛÛUÜ]J ÌÍÒÙY   [ÈÔBÑ[B[ÈÝÜ

BP]]Ò]Ù]Ü[Û ÌÎNÑÕRSÛ][[ÙIÌÎNË
BUÚ[H  ÌÍÒÙYBIÌÍÓÙÏQÕRQÙ]ÙÊ
BBRY    ÌÍÓÙÈH ÌÍÐÛÜÙH[  ÌÍÒÙYHBTÛY
L
BUÑ[B[[ÂB[ÈÛÛ[YJ
BIÌÍÒÙYH[[
Link to comment
Share on other sites

This is the sort of thing I meant

AutoItSetOption('GUIOnEventMode', 1)
Global $Keep = 1
GUICreate('sample', 200, 100)
$Open = GUICtrlCreateButton('Stop', 10, 10, 100, 20)
GUICtrlSetOnEvent(-1, 'Stop')
$Close = GUICtrlCreateButton('Continue', 10, 50, 100, 20)
GUICtrlSetOnEvent(-1, 'Continue')
GUISetState()
GUISetOnEvent(-3,"alldone")
While 1
    Sleep(1000)
    ConsoleWrite($Keep & @CRLF)
    If $Keep = 0 Then
        RealStop()
        $Keep = 1
    EndIf
    
WEnd

Func Stop()
    $Keep = 0
EndFunc  ;==>Stop

Func RealStop()
    
    While $Keep = 0
        Sleep(10)
    WEnd
EndFunc  ;==>RealStop

Func Continue()
    $Keep = 1
EndFunc  ;==>Continue

Func AllDOne()
    
    exit
    
EndFunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Ah, ok, I get it.

You "shorten" the functions to setting variables and use them to call the real (bigger) ones.

Although this "stretches" the code a little bit compared to a simple GuiGetMsg-Loop.

Hmm, I think I'll give it a try, if it's not working, I'll switch back to loops again.

Thanks for your support.

Edit: After some thinking, I edited your example to

; mainloop
While 1
    Sleep(1000)
    If $ExecuteNow <> '' Then Call($ExecuteNow)
WEnd

; trigger
Func Stop()
    If $ExecuteNow = '' Then $ExecuteNow = 'RealStop'
EndFunc  ;==>Stop

; real called function
Func RealStop()
   $ExecuteNow=''
    While $Keep = 0
        Sleep(10)
    WEnd
EndFunc  ;==>RealStop

I think that's a good solution that I will use for my script.

Edited by dabus
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...