Jump to content

GUI Responsiveness


cmb99
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...