Jump to content

Problem with operation of the ControlClick


 Share

Go to solution Solved by SmOke_N,

Recommended Posts

Why in this code ControlClick does not always work. Once running, once no.

Hotkey is pressed while the activity of another window.

ldG4j1T.jpg

#include <GuiEdit.au3>
#include <ScrollBarsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Name", 615, 200, -1, -1, $GUI_SS_DEFAULT_GUI, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
$OutputEdit = GUICtrlCreateEdit("", 8, 8, 593, 129, $WS_VSCROLL)
$Button2 = GUICtrlCreateButton("Test", 100, 152, 75, 25)
GUISetState(@SW_SHOW)

HotKeySet("#q", "Start")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            GUISetState(@SW_HIDE)
            PrintMessage("OK")
            GUISetState(@SW_SHOW)
            _GUICtrlEdit_Scroll($OutputEdit, $SB_SCROLLCARET)
    EndSwitch
WEnd

Func PrintMessage($Message)
    GUICtrlSetData($OutputEdit, $Message & @CRLF, True)
EndFunc   ;==>PrintMessage

Func Start()
    PrintMessage("Hotkey")
    ControlClick($Form1, "", $Button2, "left")
EndFunc   ;==>Start
Link to comment
Share on other sites

  • Moderators
  • Solution

Func Start()
    PrintMessage("Hotkey")
    ControlFocus($Form1, "", $Button2)
    ControlClick($Form1, "", $Button2, "left")
EndFunc   ;==>Start

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Do you work 100% of the time when you have no focus?

Kidding of course... in theory, of course you're right.  But there are a lot of things going on your pc at any given moment, always best to take every precaution.

I'm sure the message is sent, but was it received is the question.

All of these functions have return values and most have error/extended values.  I only offer solutions if no one is going to bother to check those themselves ;) .

Edit:

Keep in mind as well, that his GUI is hidden at this time, so that plays a factor as well.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

@mike2003, good deal.

@sorrybutimanewbie

His example merely proves that the message que from AutoIt's GUI is not processing the click request when hidden or has lost of focus to the GUI.  Which I'm sure you, I, and countless others have experienced.

 
So this leaves us with a dilemma, do I focus all my energy on trying to contemplate why the windows message que isn't working correctly (yes if you have the time and don't need to move forward on your project quickly) or do I activate my window or focus on my control to get the job done.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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