Sign in to follow this  
Followers 0
johns420

ControlClick

17 posts in this topic

I am having an issue with the ControlClick() command. In the window that I am trying to click in, there is not a control ID for me to use. How to I get around this?

Share this post


Link to post
Share on other sites



I am having an issue with the ControlClick() command. In the window that I am trying to click in, there is not a control ID for me to use. How to I get around this?

Could you give a bit more description? A few things come to mind, but if you give a bit more description I can narrow my ideas.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

Try using the ClassNameNN


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

also try

AnyGUI (http://www.autoitscript.com/forum/index.php?showtopic=9517&hl=AnyGUI)

or a COM of some sorts


A decision is a powerful thing

Share this post


Link to post
Share on other sites

Could you give a bit more description? A few things come to mind, but if you give a bit more description I can narrow my ideas.

Here is an example, basically, its just trying to click a spot in a paint document.

ControlClick("untitled - Paint", "", *ID Normally goes here*, "left", 1, 186, 140)

Share this post


Link to post
Share on other sites

Here is an example, basically, its just trying to click a spot in a paint document.

ControlClick("untitled - Paint", "", *ID Normally goes here*, "left", 1, 186, 140)

Provide the Output pane information from Au3Info

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

I agree with smoke_n and also are those coors client,window, or screen?


A decision is a powerful thing

Share this post


Link to post
Share on other sites

This might give a better understanding on how to use the x and y coords... the coord for the controls start at 0(x-Coord) and go to the width and 0(Y-coord) to the Height of the control.

Global $HGUI, $HBUTTON, $HBUTTON2, $aCPos, $iXPos, $iYPos
$HGUI = GUICreate('')
$HBUTTON = GUICtrlCreateButton('CLICK WITH MOUSE', 100, 10, 200, 25)
$HBUTTON2 = GUICtrlCreateButton('BUTTON TO CLICK', 100, 40, 200, 25)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $HBUTTON
            $aCPos = ControlGetPos($HGUI, '', 'Button1')
            If IsArray($aCPos) Then
                $iXPos = Random(0, $aCPos[2], 1)
                $iYPos = Random(0, $aCPos[3], 1)
                ControlClick($HGUI, '', 'Button2', 'Left', 1, $iXPos, $iYPos)
            EndIf
        Case $HBUTTON2
            MsgBox(64, 'Success', 'ControlClicked Button 2' & @CRLF & _
                'X Pos Clicked = ' & $iXPos & @CRLF & _
                'Y Pos Clicked = ' & $iYPos)
    EndSwitch
WEnd

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

I agree with smoke_n and also are those coors client,window, or screen?

those coors were window coors.

Share this post


Link to post
Share on other sites

This might give a better understanding on how to use the x and y coords... the coord for the controls start at 0(x-Coord) and go to the width and 0(Y-coord) to the Height of the control.

Global $HGUI, $HBUTTON, $HBUTTON2, $aCPos, $iXPos, $iYPos
$HGUI = GUICreate('')
$HBUTTON = GUICtrlCreateButton('CLICK WITH MOUSE', 100, 10, 200, 25)
$HBUTTON2 = GUICtrlCreateButton('BUTTON TO CLICK', 100, 40, 200, 25)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $HBUTTON
            $aCPos = ControlGetPos($HGUI, '', 'Button1')
            If IsArray($aCPos) Then
                $iXPos = Random(0, $aCPos[2], 1)
                $iYPos = Random(0, $aCPos[3], 1)
                ControlClick($HGUI, '', 'Button2', 'Left', 1, $iXPos, $iYPos)
            EndIf
        Case $HBUTTON2
            MsgBox(64, 'Success', 'ControlClicked Button 2' & @CRLF & _
                'X Pos Clicked = ' & $iXPos & @CRLF & _
                'Y Pos Clicked = ' & $iYPos)
    EndSwitch
WEnd

I understand how to use the command if you have the control ID, which in your code is 'Button2', my question is what if there is no control ID, how do you have it click at the specific window coordinates?

Share this post


Link to post
Share on other sites

There are several different ways you can do that. It depends to on if the position is static or dynamic. In other words what you want does it move occasionally or is it always in the same place?

For a general static click place, look up

MouseClick()

Opt("MouseCoordMode", 1) ;1=absolute, 0=relative, 2=client

Opt("WinSearchChildren", 1) ;0=no, 1=search children also

You may be like "duh." In which case, I'm misunderstanding what you're attempting to do.

You can also sometimes use the classID

Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Advanced Window Descriptions

A special description can be used as the window title parameter. This description can be used to identify a window by the following properties:

TITLE - Window title

CLASS - The internal window classname

REGEXPTITLE - Window title using a regular expression

LAST - Last window used in a previous AutoIt command

ACTIVE - Currently active window

INSTANCE - The 1-based instance when all given properties match

Other times, ANY GUI works really well.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

There are several different ways you can do that. It depends to on if the position is static or dynamic. In other words what you want does it move occasionally or is it always in the same place?

For a general static click place, look up

MouseClick()

Opt("MouseCoordMode", 1) ;1=absolute, 0=relative, 2=client

Opt("WinSearchChildren", 1) ;0=no, 1=search children also

You may be like "duh." In which case, I'm misunderstanding what you're attempting to do.

You can also sometimes use the classID

Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Other times, ANY GUI works really well.

The window I am trying to click in is a static size but the location may vary. That is why I wanted to use the CommandClick() instead of MouseClick(). From what I have read about MouseClick(), it can't focus on a specific window like ControlClick() can. If I am wrong please show me an example of how to use MouseClick() to specify the window.

As to more info on the window, It is always the same size and the buttons in the window are always in the same place, but the location of the window may change location due to different resolutions or users dragging the window around.

Share this post


Link to post
Share on other sites

Opt("WinTitleMatchMode", 4) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

;HERE IS THE KEY >> 
Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client
;==above is the key


Run('mspaint.exe')
Local $rX = Random(25,530)
Local $rY = Random(25,725)
Local $window = "untitled - Paint"
WinWaitActive($window )
WinMove($window,'',$rX,$rY)
Sleep(1000) ; makes sure it loads

MouseClick('left',11,168)
MouseClickDrag('left',80,168,200,250)


A decision is a powerful thing

Share this post


Link to post
Share on other sites

Opt("WinTitleMatchMode", 4) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

;HERE IS THE KEY >> 
Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client
;==above is the key
Run('mspaint.exe')
Local $rX = Random(25,530)
Local $rY = Random(25,725)
Local $window = "untitled - Paint"
WinWaitActive($window )
WinMove($window,'',$rX,$rY)
Sleep(1000) ; makes sure it loads

MouseClick('left',11,168)
MouseClickDrag('left',80,168,200,250)

Perfect, Thank you very much for your help. The Opt() lines are new to me. Thanks again for your help.

Share this post


Link to post
Share on other sites

Perfect, Thank you very much for your help. The Opt() lines are new to me. Thanks again for your help.

Cool I'm glad I could help. It's nice to be able to share what I've learned.

The Opt() command is really helpful. I strongly recommend looking that up in the manual. There are several different ones you can use.


A decision is a powerful thing

Share this post


Link to post
Share on other sites

Cool I'm glad I could help. It's nice to be able to share what I've learned.

The Opt() command is really helpful. I strongly recommend looking that up in the manual. There are several different ones you can use.

I will definatly look into it. Thanks again for the help.

Share this post


Link to post
Share on other sites

I will definatly look into it. Thanks again for the help.

No prob! That's why nearly all of us are on here - to help each other and advance what is being done. enjoy


A decision is a powerful thing

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