Sign in to follow this  
Followers 0
mike2003

Problem with operation of the ControlClick

7 posts in this topic

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

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

That could help, but shouldn't controlclick work on windows that has no focus?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites

According to this, shouldn't it work differently on my computer then in his, sometimes i mean? (Also I usually give focus to the window I "working on") I had similar problems with controlclick, I used send instead a few times, but Smoke_n-s solution should be better

Share this post


Link to post
Share on other sites
thank you, it works very well!

Share this post


Link to post
Share on other sites

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

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