Jump to content

How to use ControlClick ?


Recommended Posts

Hey guys,

I am learning autoit and I want my script to open IDM from desktop and it worked.

But when I want it to click on a certain pixel (the synchronized queue) using ControlClick it doesn't.

 ControlClick("Internet Download Manager 6.36","", "", "left" ,1 ,56,316)

the mouseclick function works properly:

MouseClick("left", 56,316)

 

Where is the syntax error in my controlclick funtion ? I'm using the Syntax Check and it shows no error

And what is the difference between ControlClick and MouseClick ?

Link to post
Share on other sites

Your position is not right, as you can see by yourself, controlClick use window position where as MouseClick use by default absolute screen coords.

You should not use position when you know the control id as you have.

Try something like this (I always recommend using handle as you can verify with Au3info.exe tool if they match)

#include <Constants.au3>

Local $hWnd = WinGetHandle("Internet Download Manager 6.36")
If Not $hWnd Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error on win title")
ConsoleWrite($hWnd & @CRLF)
Local $hCtrl = ControlGetHandle($hWnd, "", "Button2")
If Not $hCtrl Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error on button2")
ConsoleWrite($hCtrl & @CRLF)
Local $iRet = ControlClick($hWnd, "", $hCtrl)
ConsoleWrite($iRet & @CRLF)

When you post code, use <> as shown

Edited by Nine
Link to post
Share on other sites
2 hours ago, Danp2 said:

Try like this --

ControlClick("Internet Download Manager","", "[CLASS:Button; INSTANCE:2]")

 

Didn't work
Does " /ErrorStdOut" count as an error ?
anyway  here is my simple script:

 

$variable1= TimerInit()


$checkWin = WinExists("Internet Download Manager 6.36")
Sleep(2000)
If $checkWin = 0 Then
   ShellExecute("Internet Download Manager" , "", @DesktopDir)
   Sleep(8000)

ElseIf $checkWin = 1 Then
   sleep(3000)
   ControlClick("Internet Download Manager","", "[CLASS:Button; INSTANCE:2]")


EndIf
$variable2= TimerDiff($variable1)
MsgBox(0, "lesson 3", "beinning time: " & $variable1 & @CRLF & "total bot time: " & $variable2)

image.png

Link to post
Share on other sites
2 hours ago, Nine said:

Your position is not right, as you can see by yourself, controlClick use window position where as MouseClick use by default absolute screen coords.

You should not use position when you know the control id as you have.

Try something like this (I always recommend using handle as you can verify with Au3info.exe tool if they match)

#include <Constants.au3>

Local $hWnd = WinGetHandle("Internet Download Manager 6.36")
If Not $hWnd Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error on win title")
ConsoleWrite($hWnd & @CRLF)
Local $hCtrl = ControlGetHandle($hWnd, "", "Button2")
If Not $hCtrl Then Exit MsgBox($MB_SYSTEMMODAL, "", "Error on button2")
ConsoleWrite($hCtrl & @CRLF)
Local $iRet = ControlClick($hWnd, "", $hCtrl)
ConsoleWrite($iRet & @CRLF)

When you post code, use <> as shown

It'll take me some time to grasp this because I'm only few lessons in and I don't know all these commands. But thanks for the help this will push me to learn faster.

Link to post
Share on other sites
13 minutes ago, xkazz said:

Does " /ErrorStdOut" count as an error ?

No it is a standard message from Scite...

Link to post
Share on other sites
1 hour ago, xkazz said:

Didn't work

There are numerous reasons why that could be. Try checking to see what value is returned by the function call. Also, is the target app running under the same user or as an Admin?

You could try adding #RequireAdmin to the beginning of your script to see if that has any effect.

Link to post
Share on other sites
On 7/19/2021 at 10:02 PM, Danp2 said:

There are numerous reasons why that could be. Try checking to see what value is returned by the function call. Also, is the target app running under the same user or as an Admin?

You could try adding #RequireAdmin to the beginning of your script to see if that has any effect.

I only have one user in my pc.
 

Sleep(2000)
;~      ControlClick("Internet Download Manager 6.36", "", "[ControlClick Coords:49,211]", )
;~      ControlClick ("Internet Download Manager 6.36", "", [ID:1280],left ,1 ,11,10)
;~      ControlClick("Internet Download Manager 6.36", "", 1280)
;~      ControlClick("Internet Download Manager 6.36", "", "[CLASS:Button; INSTANCE:2]", "left" , 1, 49 , 211)

here I typed all what I could find about this subject

I used them all one by one and nothing changed. And I think ControlClick is a more stable version of MouseClick since changing the window position will ruin the execution of MouseClick

Link to post
Share on other sites
3 minutes ago, Danp2 said:

Ok... so did you try adding this one line to the top of your script and then running it? If so, did the ControlClick work?

I did with all the 5 possible lines one by one. It showed the "script is running as admin" in all of them except the 1st one because I somehow typed it wrong.

Still didn't click where I want it to.

Link to post
Share on other sites

With the IDM app already loaded, please run each of the following code snippets and post the results from the Scite output window --

$iResult = ControlClick("Internet Download Manager","", "[CLASS:Button; INSTANCE:2]")
ConsoleWrite("Non-admin result = " & $iResult & @crlf)

 

#RequireAdmin

$iResult = ControlClick("Internet Download Manager","", "[CLASS:Button; INSTANCE:2]")
ConsoleWrite("Admin result = " & $iResult & @crlf)

 

Link to post
Share on other sites
2 minutes ago, Danp2 said:

With the IDM app already loaded, please run each of the following code snippets and post the results from the Scite output window --

$iResult = ControlClick("Internet Download Manager","", "[CLASS:Button; INSTANCE:2]")
ConsoleWrite("Non-admin result = " & $iResult & @crlf)

 

#RequireAdmin

$iResult = ControlClick("Internet Download Manager","", "[CLASS:Button; INSTANCE:2]")
ConsoleWrite("Admin result = " & $iResult & @crlf)

 

Thanks again for your efforts.

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\Zak\Documents\test333 l3.au3"    
Non-admin result = 1
>Exit code: 0    Time: 1.306

 

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\Zak\Documents\test333 l3.au3"    
Admin result = 1
>Exit code: 0    Time: 1.306

 

I think I'll just avoid this command from now on. I'll use mouseclick mousemove winsetstate and winmove. Do you think they are enough?

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...