Sign in to follow this  
Followers 0
RockyWang

How to determine Controlid for ControlClick()?

8 posts in this topic

#1 ·  Posted (edited)

Hi,

I just begin to learn Autoit, and try to make a simple script to left-click in a program which works background.

So I opened and maximized a text file called "123.txt" and try to click the close button.

Below is my simple code, I use $a to know whether the operation is successful. 1 denotes success.

The pixel x= 1322, y = 14 should be the CLOSE button on the right top corner.

$a = ControlClick ( "123.txt - Notepad", "", "what should I put in here?","left",1,1322, 14 )
MsgBox(0,"result", $a)

I have no idea of what to put in the control parameter.

The infomation I got by AutoIt Window Info as follows:

---------------------------------------------------------------------------

>>>> Window <<<<

Title: 123.txt - Notepad

Class: Notepad

Position: -9, -9

Size: 1384, 786

Style: 0x15CF0000

ExStyle: 0x00000110

Handle: 0x00000000000806B8

>>>> Control <<<<

Class: Edit

Instance: 1

ClassnameNN: Edit1

Name:

Advanced (Class): [CLASS:Edit; INSTANCE:1]

ID: 15

Text:

Position: 0, 0

Size: 1366, 716

ControlClick Coords: 651, 358

Style: 0x50200104

ExStyle: 0x00000200

Handle: 0x00000000001F0800

---------------------------------------------------------------------------

I've tried "", and 15 and " [CLASS:Edit; INSTANCE:1]", the controlclick returns 1 for all, but the text file is still there(it should be closed).

So, can anyone help me?

thanks!

Edited by RockyWang

Share this post


Link to post
Share on other sites



Welcome to the forums RockyWang! :oops:

ControlClick function does not work with X and Y on minimized windows. You need to find a specific control (e.g. by using the AutoIt Window Info tool) and then specify it in ControlClick. In this situation, the 'close button' can't be clicked when window is minimized. You can use script called MouseClickPlus to click things on minimized windows.

Here is MouseClickPlus (but I'm not sure if it works - never tried):

;===============================================================================
  ;
  ; Function Name:  _MouseClickPlus()
  ; Version added:  0.1
  ; Description:    Sends a click to window, not entirely accurate, but works
  ;              minimized.
  ; Parameter(s):   $Window  =  Title of the window to send click to
  ;              $Button     =  "left" or "right" mouse button
  ;              $X       =  X coordinate
  ;              $Y       =  Y coordinate
  ;              $Clicks     =  Number of clicks to send
  ; Remarks:        You MUST be in "MouseCoordMode" 0 to use this without bugs.
  ; Author(s):    Insolence <insolence_9@yahoo.com>
  ;
  ;===============================================================================
Func _MouseClickPlus($Window, $Button = "left", $X = "", $Y = "", $Clicks = 1)
    Local $MK_LBUTTON      =  0x0001
    Local $WM_LBUTTONDOWN   =  0x0201
    Local $WM_LBUTTONUP  =  0x0202
   
    Local $MK_RBUTTON      =  0x0002  
    Local $WM_RBUTTONDOWN   =  0x0204
    Local $WM_RBUTTONUP  =  0x0205

    Local $WM_MOUSEMOVE  =  0x0200
   
    Local $i                = 0
   
    Select
    Case $Button = "left"
       $Button   =  $MK_LBUTTON
       $ButtonDown =  $WM_LBUTTONDOWN
       $ButtonUp   =  $WM_LBUTTONUP
    Case $Button = "right"
       $Button   =  $MK_RBUTTON
       $ButtonDown =  $WM_RBUTTONDOWN
       $ButtonUp   =  $WM_RBUTTONUP
    EndSelect
   
    If $X = "" OR $Y = "" Then
       $MouseCoord = MouseGetPos()
       $X = $MouseCoord[0]
       $Y = $MouseCoord[1]
    EndIf
   
    For $i = 1 to $Clicks
       DllCall("user32.dll", "int", "SendMessage", _
          "hwnd",  WinGetHandle( $Window ), _
          "int",   $WM_MOUSEMOVE, _
          "int",   0, _
          "long",  _MakeLong($X, $Y))
         
       DllCall("user32.dll", "int", "SendMessage", _
          "hwnd",  WinGetHandle( $Window ), _
          "int",   $ButtonDown, _
          "int",   $Button, _
          "long",  _MakeLong($X, $Y))
         
       DllCall("user32.dll", "int", "SendMessage", _
          "hwnd",  WinGetHandle( $Window ), _
          "int",   $ButtonUp, _
          "int",   $Button, _
          "long",  _MakeLong($X, $Y))
    Next
EndFunc




Func _MakeLong($LoWord,$HiWord)
    Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc

If you don't know, read the manual, browse forums, use search and use google: "site:autoitscript.com <what do you need?>" :bye:


[indent=3][/indent]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Welcome to the forums RockyWang! :oops:

ControlClick function does not work with X and Y on minimized windows. You need to find a specific control (e.g. by using the AutoIt Window Info tool) and then specify it in ControlClick. In this situation, the 'close button' can't be clicked when window is minimized. You can use script called MouseClickPlus to click things on minimized windows.

Here is MouseClickPlus (but I'm not sure if it works - never tried):

;===============================================================================
  ;
  ; Function Name:  _MouseClickPlus()
  ; Version added:  0.1
  ; Description:    Sends a click to window, not entirely accurate, but works
  ;              minimized.
  ; Parameter(s):   $Window  =  Title of the window to send click to
  ;              $Button     =  "left" or "right" mouse button
  ;              $X       =  X coordinate
  ;              $Y       =  Y coordinate
  ;              $Clicks     =  Number of clicks to send
  ; Remarks:        You MUST be in "MouseCoordMode" 0 to use this without bugs.
  ; Author(s):    Insolence <insolence_9@yahoo.com>
  ;
  ;===============================================================================
Func _MouseClickPlus($Window, $Button = "left", $X = "", $Y = "", $Clicks = 1)
    Local $MK_LBUTTON      =  0x0001
    Local $WM_LBUTTONDOWN   =  0x0201
    Local $WM_LBUTTONUP  =  0x0202
  
    Local $MK_RBUTTON      =  0x0002  
    Local $WM_RBUTTONDOWN   =  0x0204
    Local $WM_RBUTTONUP  =  0x0205

    Local $WM_MOUSEMOVE  =  0x0200
  
    Local $i                = 0
  
    Select
    Case $Button = "left"
       $Button   =  $MK_LBUTTON
       $ButtonDown =  $WM_LBUTTONDOWN
       $ButtonUp   =  $WM_LBUTTONUP
    Case $Button = "right"
       $Button   =  $MK_RBUTTON
       $ButtonDown =  $WM_RBUTTONDOWN
       $ButtonUp   =  $WM_RBUTTONUP
    EndSelect
  
    If $X = "" OR $Y = "" Then
       $MouseCoord = MouseGetPos()
       $X = $MouseCoord[0]
       $Y = $MouseCoord[1]
    EndIf
  
    For $i = 1 to $Clicks
       DllCall("user32.dll", "int", "SendMessage", _
          "hwnd",  WinGetHandle( $Window ), _
          "int",   $WM_MOUSEMOVE, _
          "int",   0, _
          "long",  _MakeLong($X, $Y))
        
       DllCall("user32.dll", "int", "SendMessage", _
          "hwnd",  WinGetHandle( $Window ), _
          "int",   $ButtonDown, _
          "int",   $Button, _
          "long",  _MakeLong($X, $Y))
        
       DllCall("user32.dll", "int", "SendMessage", _
          "hwnd",  WinGetHandle( $Window ), _
          "int",   $ButtonUp, _
          "int",   $Button, _
          "long",  _MakeLong($X, $Y))
    Next
EndFunc




Func _MakeLong($LoWord,$HiWord)
    Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc

If you don't know, read the manual, browse forums, use search and use google: "site:autoitscript.com <what do you need?>" :bye:

Great thanks for your reply but I mean maximized window, not minimized. Sorry for my ambiguious word "background".

What I mean is to close a already maximized text file while at the same time I'm browsing Firefox or doing whatever.

Edited by RockyWang

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You can close it by many other functions.

WinKill("Untitled - Notepad")

- This one forces close (works like a terminate process)

WinClose("Untitled - Notepad")

- This one closes standard way - just like clicking the "close button"

Press F1 in SciTE editor for help - it's a great tool, rly.

If you don't know the window name, use Class instead:

WinKill("[CLASS:Notepad]")
Edited by VixinG

[indent=3][/indent]

Share this post


Link to post
Share on other sites

You can close it by many other functions.

WinKill("Untitled - Notepad")

- This one forces close (works like a terminate process)

WinClose("Untitled - Notepad")

- This one closes standard way - just like clicking the "close button"

Press F1 in SciTE editor for help - it's a great tool, rly.

If you don't know the window name, use Class instead:

WinKill("[CLASS:Notepad]")

I know there are close functions, my point is how to CLICK a certian place in another window. I just take "Close " as a random example.

Share this post


Link to post
Share on other sites

my point is how to CLICK a certian place in another window. I just take "Close " as a random example.

What I mean is to close a already maximized text file while at the same time I'm browsing Firefox or doing whatever.

Lol man :bye: I'm confused. BUT

Here's something:

In a "normal fullscreen program window" a word is something you cannot click and have something happen.

What you can click are controls in the "normal fullscreen program window".

Use window info tool (which can be found in the start menu under Autoit3 to find the control.

That means that you can't click something in background window that isn't a control :oops:


[indent=3][/indent]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Lol man :bye: I'm confused. BUT

Here's something:

That means that you can't click something in background window that isn't a control :oops:

Ok, great thanks for your patience.

So make my points clearer:

Is it possible that to click at certain pixel(for example to click a button on a flash player) in another opened window(normal sized,not fullscreen and not minimized) using whatever function? and use what function?

Edited by RockyWang

Share this post


Link to post
Share on other sites

If it is not a control (check with AutoIt window info) or an active window (ACTIVE) I believe it's not possible.


[indent=3][/indent]

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