mike2003 Posted January 23, 2015 Share Posted January 23, 2015 Why in this code ControlClick does not always work. Once running, once no. Hotkey is pressed while the activity of another window. #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 More sharing options...
Moderators Solution SmOke_N Posted January 23, 2015 Moderators Solution Share Posted January 23, 2015 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 More sharing options...
SorryButImaNewbie Posted January 23, 2015 Share Posted January 23, 2015 That could help, but shouldn't controlclick work on windows that has no focus? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 23, 2015 Moderators Share Posted January 23, 2015 (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 January 23, 2015 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 More sharing options...
SorryButImaNewbie Posted January 23, 2015 Share Posted January 23, 2015 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 Link to comment Share on other sites More sharing options...
mike2003 Posted January 23, 2015 Author Share Posted January 23, 2015 thank you, it works very well! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 23, 2015 Moderators Share Posted January 23, 2015 @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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now