Jump to content
Mavnus04

GUIGetMsg not clearing the event.

Recommended Posts

Mavnus04

I have written a program to help me automate a lot of testing that I have to do.  The program fully runs without any errors.  However, every now and then it seems a button press gets stuck.  My code will re-run the code I have in a button.  In the below, if I press 'Run Main Script', it will run and finish usually within 24 hours.  Then it exits back to the main while loop and automatically runs the 'Run Main Script' again. 

Since my code is very long, here is a condensed version just to give you an idea of what I have:

;Main GUI for user interaction
Func MainGui()
    $butTest = GUICtrlCreateButton("Test Main Script", 115, 130, 100, 25)
    $butRun    = GUICtrlCreateButton("Run Main Script", 220, 130, 100, 25)
    
    While 1
        Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE    ;close GUI
            $posMainGui = WinGetPos($MainGui)
            _FileWriteFromArray(@ScriptDir & '\PosMainGui.ini', $posMainGui)
            ExitLoop(1)
            
        Case $butTest            ;Test MainScript
            GUICtrlSetState($MainGui, $GUI_DISABLE)
            RunMainScript(True)
            GUICtrlSetState($MainGui, $GUI_ENABLE)
            _WinWaitActivate($MainGui)

        Case $butRun            ;Run MainScript
            GUICtrlSetState($MainGui, $GUI_DISABLE)
            RunMainScript(False)
            GUICtrlSetState($MainGui, $GUI_ENABLE)
            _WinWaitActivate($MainGui)
        
        EndSwitch

    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($MainGui)
EndFunc

;Runs $Exe until it completes
;Returns: exitcode of the process
Func _RunWait($Exe)
    ;Runs other autoit files
    ;not pasting this code...
    Return $exitCode
EndFunc

;--Main Loop--
Func RunMainScript($Testing)
    ;Opens and saves files
    ;Checks $Testing boolean
    ;while loop
        ;for loop
            ;calls _RunWait 
        ;next
    ;wend
    ;another while loop
        ;more for loops
            ;calls _RunWait 
        ;next
    ;wend
EndFunc

Share this post


Link to post
Share on other sites
Jos
9 minutes ago, Mavnus04 said:

Since my code is very long, here is a condensed version just to give you an idea of what I have

Can you get the described issue running this version as I see nothing in there that could cause the extra button presses?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Mavnus04
1 hour ago, Jos said:

Can you get the described issue running this version as I see nothing in there that could cause the extra button presses?

Jos

I haven't tested the above code.  Also highly doubt it. 
Just didn't want to post 1500+ lines of code that I use for work.  I was trying to give an idea of what I am seeing to see if anyone else has something similar. 

Share this post


Link to post
Share on other sites
Mavnus04
#include <GUIConstantsEx.au3>
#include <Misc.au3>

Local $bW=115, $bH=25
$RecGUI = GUICreate("Record & Test", 500, 400)
$butRec = GUICtrlCreateButton("Record Selected", 10, 10, $bW, $bH)
$lblText = GUICtrlCreateLabel("", 10, 50, 300, 25)
$lblText2 = GUICtrlCreateLabel("", 10, 100, 300, 25)
GUISetState(@SW_SHOW, $RecGUI)

While 1
    Switch GUIGetMsg()
        Case $butRec
            Local $userDLL = DllOpen("user32.dll")
            GUICtrlSetData($lblText, "Press F2 to exit button loop")
            GUICtrlSetData($lblText2, "Press F3 to record clicking")
            Do
                If(_IsPressed("72",$userDLL)) Then  ;F3 for clicks
                    $CurrWinName = WinGetTitle("[active]")
                    ConsoleWrite("Before click: " & $CurrWinName & @CRLF)
                    ToolTip("Click on window")
                    Do
                        Sleep(10)
                    Until(_IsPressed("01",$userDLL))
                    Sleep(50)
                    $CurrWinName = WinGetTitle("[active]")
                    ToolTip("")
                    While _IsPressed("01",$userDLL)
                        Sleep(10)
                    WEnd
                    ConsoleWrite("After click: " & $CurrWinName & @CRLF)
                EndIf

            Until (_IsPressed("71",$userDLL) )  ;Stop on F2 press

            GUICtrlSetData($lblText, "")
            GUICtrlSetData($lblText2, "")

            DllClose($userDLL)
            ToolTip("")

        Case $GUI_EVENT_CLOSE
            ExitLoop(1)

    EndSwitch
WEnd
GUIDelete($RecGUI)

I finally got around to reducing a section of my code to re-create this problem.  It happens maybe 1/20 times?  It is hard to do.  But every once in a while, the $butRec will activate itself after I have left it's loop. 

Share this post


Link to post
Share on other sites
AutoBert

It's a ugly: Turn off the GuiGetMsg-Mode with

Opt("GUIOnEventMode", 1)

everytime you begin looping with _IsPressed and after ending the looping just turn on with

Opt("GUIOnEventMode", 0)

 

Share this post


Link to post
Share on other sites
qwert

I just noticed this thread and want to mention that I've been experiencing the same kind of thing when processing right mouse clicks ($GUI_EVENT_SECONDARYUP).

About once every 6 or 8 clicks, my script processes what I've termed a bounce click.  I have no reason to think it's the mouse, itself because the effect never occurs with other software.

This led me to wonder: what's the proper way to clear any pending events for a GUI?  Is turning off the mode the correct approach?

For my particular case, I'd like to be able to "clear the decks" right before the Wend statement if ANY event has been received and processed.

  • Like 1

Share this post


Link to post
Share on other sites
Mavnus04

@AutoBert, Sorry what line would those go on?  Can you show an example?

Share this post


Link to post
Share on other sites
AutoBert
28 minutes ago, Mavnus04 said:

Can you show an example?

#include <GUIConstantsEx.au3>
#include <Misc.au3>

Local $bW = 115, $bH = 25
$RecGUI = GUICreate("Record & Test", 500, 400)
$butRec = GUICtrlCreateButton("Record Selected", 10, 10, $bW, $bH)
$lblText = GUICtrlCreateLabel("", 10, 50, 300, 25)
$lblText2 = GUICtrlCreateLabel("", 10, 100, 300, 25)
GUISetState(@SW_SHOW, $RecGUI)

While 1
    Switch GUIGetMsg()
        Case $butRec
            Local $userDLL = DllOpen("user32.dll")
            GUICtrlSetData($lblText, "Press F2 to exit button loop")
            GUICtrlSetData($lblText2, "Press F3 to record clicking")
            Opt("GUIOnEventMode", 1)
            Do
                If (_IsPressed("72", $userDLL)) Then ;F3 for clicks
                    $CurrWinName = WinGetTitle("[active]")
                    ConsoleWrite("Before click: " & $CurrWinName & @CRLF)
                    ToolTip("Click on window")
                    Do
                        Sleep(10)
                    Until (_IsPressed("01", $userDLL))
                    Sleep(50)
                    $CurrWinName = WinGetTitle("[active]")
                    ToolTip("")
                    While _IsPressed("01", $userDLL)
                        Sleep(10)
                    WEnd
                    ConsoleWrite("After click: " & $CurrWinName & @CRLF)
                EndIf

            Until (_IsPressed("71", $userDLL)) ;Stop on F2 press
            Opt("GUIOnEventMode", 0)
            GUICtrlSetData($lblText, "")
            GUICtrlSetData($lblText2, "")

            DllClose($userDLL)
            ToolTip("")

        Case $GUI_EVENT_CLOSE
            ExitLoop (1)

    EndSwitch
WEnd
GUIDelete($RecGUI)

 

  • Thanks 1

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

×