Sign in to follow this  
Followers 0
cmb99

GUI Responsiveness

3 posts in this topic

#1 ·  Posted (edited)

Why does this script never repsond to mouse clicks (either, buttons or closing):

#include <GUIConstants.au3>
HotKeySet("^!x", "MyExit")
Opt("MouseCoordMode", 0)
Opt("WinWaitDelay", 0)
GUICreate("ActiveScript", 165, 66)
$startButton = GUICtrlCreateButton("Start", 20, 22, 60)
$stopButton = GUICtrlCreateButton("Stop", 90, 22, 60)
GUISetState(@SW_SHOW)
WinSetOnTop("ActiveScript", "", 1)
$runState = 1
$winList = WinList()
$numWin = $winList[0][0]

While 1
    $GUIMsg = GUIGetMsg()
    
    Select
        Case $GUIMsg = $startButton
            $runState = 1
        Case $GUIMsg = $stopButton
            $runState = 0
        Case $GUIMsg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
    
    If $runState Then   ; Loop thrugh windows
        $mousePos = MouseGetPos()
        For $i = 1 to $numWin
            If StringInStr($winList[$i][0], "mywin") Then
                WinActivate($winList[$i][0]) 
                Send("{ENTER}")
            EndIf
        Next
        MouseMove($mousePos[0], $mousePos[1], 0)
    EndIf
    Sleep(3500)
Wend

Func MyExit()
    Exit 
EndFunc

When I set Sleep to a much shorter time interval, paradoxically, the buttons start working, but this is much too much cpu load.

Edited by cmb99

Share this post


Link to post
Share on other sites



what about just running the update portion only every 3.5 seconds?

For example like the below or using adlibenable():

#include <GUIConstants.au3>
HotKeySet("^!x", "MyExit")
Opt("MouseCoordMode", 0)
Opt("WinWaitDelay", 0)
GUICreate("ActiveScript", 165, 66)
$startButton = GUICtrlCreateButton("Start", 20, 22, 60)
$stopButton = GUICtrlCreateButton("Stop", 90, 22, 60)
GUISetState(@SW_SHOW)
WinSetOnTop("ActiveScript", "", 1)
$runState = 1
$winList = WinList()
$numWin = $winList[0][0]
$updtimer = TimerInit()
While 1
    $GUIMsg = GUIGetMsg()
    
    Select
        Case $GUIMsg = $startButton
            $runState = 1
        Case $GUIMsg = $stopButton
            $runState = 0
        Case $GUIMsg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
    
    If $runState and TimerDiff($updtimer) > 3500 Then  ; Loop thrugh windows
        $updtimer = TimerInit()
        $mousePos = MouseGetPos()
        For $i = 1 to $numWin
            If StringInStr($winList[$i][0], "mywin") Then
                WinActivate($winList[$i][0]) 
                Send("{ENTER}")
            EndIf
        Next
        MouseMove($mousePos[0], $mousePos[1], 0)
    EndIf
Wend

Func MyExit()
    Exit 
EndFunc

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

Share this post


Link to post
Share on other sites

Wow, fast response! Your solution works great!

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