Jump to content

how to click correctly even though the position is changed


Recommended Posts

Hi,

I wrote a simple script using the mouseclick command to dial a digital phone. However if I shift the position of the dialer, the mouseclick will click the wrong position.

What must I do so that even if I change the position of the dialer, AutoIt is still able to mouseclick the dialer at the right position.

Thanks

___________________script_____________________

MouseClick("left", 904, 518, 1)

MouseClick("left", 868, 466, 1)

MouseClick("left", 834, 491, 1)

MouseClick("left", 860, 516, 1)

MouseClick("left", 868, 548, 1)

MouseClick("left", 868, 548, 1)

MouseClick("left", 868, 548, 1)

MouseClick("left", 786, 450, 1);press sent button

Link to comment
Share on other sites

Hi,

I wrote a simple script using the mouseclick command to dial a digital phone. However if I shift the position of the dialer, the mouseclick will click the wrong position.

What must I do so that even if I change the position of the dialer, AutoIt is still able to mouseclick the dialer at the right position.

Thanks

___________________script_____________________

MouseClick("left", 904, 518, 1)

MouseClick("left", 868, 466, 1)

MouseClick("left", 834, 491, 1)

MouseClick("left", 860, 516, 1)

MouseClick("left", 868, 548, 1)

MouseClick("left", 868, 548, 1)

MouseClick("left", 868, 548, 1)

MouseClick("left", 786, 450, 1);press sent button

Typically, you'd want to use an offset from a position that you can always retrieve, usually relative to the window with the buttons. For example, I use the _API_ClientToScreen call in Auto3Lib to convert a position that is relative to the window I'm working with into global screen coordinates that I can pass to the MouseClick function. If your dialer is a window, you should be able to do the same thing.
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Typically, you'd want to use an offset from a position that you can always retrieve, usually relative to the window with the buttons. For example, I use the _API_ClientToScreen call in Auto3Lib to convert a position that is relative to the window I'm working with into global screen coordinates that I can pass to the MouseClick function. If your dialer is a window, you should be able to do the same thing.

Thanks PaulIA,

I've downloaded and installed Auto3Lib, and I have also read _API_ClientToScreen but I still do not know how to use this command. The picture of the dialer I have attached. I do not know what must I put in $hWnd or $tPoint.

My wild guess will be :-

$hWnd = ("Program Manager"); my desktop

$tPoint = ("Digital Voice FlexiTalk"); my dialer

_API_ClientToScreen($hWnd, ByRef $tPoint)

------------ what else that I need to put here???------------------------

Thanks

__________________________________________________________________________

"Converts the client coordinates of a specified point to screen coordinates" ........ _API_ClientToScreen($hWnd, ByRef $tPoint)

Parameters

$hWnd Identifies the window that will be used for the conversion

$tPoint tagPOINT structure that contains the client coordinates to be converted

______________________________________________________________________

post-22053-1176175106_thumb.gif

Link to comment
Share on other sites

Thanks PaulIA,

I've downloaded and installed Auto3Lib, and I have also read _API_ClientToScreen but I still do not know how to use this command. The picture of the dialer I have attached. I do not know what must I put in $hWnd or $tPoint.

My wild guess will be :-

$hWnd = ("Program Manager"); my desktop

$tPoint = ("Digital Voice FlexiTalk"); my dialer

_API_ClientToScreen($hWnd, ByRef $tPoint)

------------ what else that I need to put here???------------------------

Thanks

__________________________________________________________________________

"Converts the client coordinates of a specified point to screen coordinates" ........ _API_ClientToScreen($hWnd, ByRef $tPoint)

Parameters

$hWnd Identifies the window that will be used for the conversion

$tPoint tagPOINT structure that contains the client coordinates to be converted

______________________________________________________________________

Uh.. No. :shocked: More like:

#include <A3LWinAPI.au3>

Global $hWnd, $tRect, $tPoint, $iX, $iY

; Get the handle to the dialer window
$hWnd = WinGetHandle("Digital Voice FlexiTalk")
if $hWnd = 0 then _Lib_ShowError("Did not find Digital Voice FlexiTalk")

; Get the bounds of the dialer window
$tRect = _API_GetWindowRect($hWnd)

; Get the upper left hand corner of the window
_Lib_GetXYFromPoint($tPoint, $iX, $iY)

; Move the mouse to the corner of the window
MouseMove($iX, $iY)
Edited by PaulIA
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

I just use something like this. (I think this is the kind of thing you are looking for)

$pos2 = WinGetPos("Folder Options")
              ;$position[0] is x-pos, $position[1] is y-pos
    sleep(500)
    MouseClick("left",$pos2[0]+63, $pos2[1]+259,1,0)
    sleep(1000)

All that you need to do after that is use the Active Window Info window to figure out where the top left corner of your window is and then where each button is. Then use the numbers after the pluses to click in the right spot. I have found that it works in different resolutions too.

Edited by Wolffe
Link to comment
Share on other sites

Two more possibilities:

1. Just changing the option for MouseCoordMode to 2 gives you X/Y in client area (excludes title bar and border), and should always hit the mark.

2. Use AutoIT Info tool to get the control IDs or ClassNN name of the buttons and use ControlClick() to hit 'em.

:shocked:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

-------------PaulIA's script --------------------------------

#include <A3LWinAPI.au3>

Global $hWnd, $tRect, $tPoint, $iX, $iY

; Get the handle to the dialer window

$hWnd = WinGetHandle("Digital Voice FlexiTalk")

if $hWnd = 0 then _Lib_ShowError("Did not find Digital Voice FlexiTalk")

; Get the bounds of the dialer window

$tRect = _API_GetWindowRect($hWnd)

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

Thanks a lot everybody, I will be studying everything that is posted here.

Regarding PaulIA's script,

I want to have a feel of the functions and so I insert line by line one at a time but on the forth line $tRect = _API_GetWindowRect($hWnd), I got an error. The error msg I have attached here. I've read the help files which says that the function $tRect = _API_GetWindowRect($hWnd) is to Retrieves the dimensions of the bounding rectangle of the specified window.

So what must I do with the error?

Thanks

post-22053-1176421151_thumb.jpg

Link to comment
Share on other sites

I just use something like this. (I think this is the kind of thing you are looking for)

$pos2 = WinGetPos("Folder Options")
             ;$position[0] is x-pos, $position[1] is y-pos
    sleep(500)
    MouseClick("left",$pos2[0]+63, $pos2[1]+259,1,0)
    sleep(1000)

All that you need to do after that is use the Active Window Info window to figure out where the top left corner of your window is and then where each button is. Then use the numbers after the pluses to click in the right spot. I have found that it works in different resolutions too.

Thanks Wolffe for sharing,

Yes, I tried your method and it works very well. Now I can place the dialer anywhere and the mouse will still click at the correct position. I've learn something new about WinGetPos and I am very happy and excited. The problem with the script below is that I have to do some manual calculation for eg, using the "active window info", I get the actual mouse 'Y' position minus the dialer 'Y' position etc......

Now I will explore the method shown by PaulIA.

__________________ script to dial _____________________________

$position = WinGetPos ( "Digital Voice FlexiTalk")

;$position[0] = x position, $position[1]= y axis

MouseClick ("left",$position[0] + 393,$position[1]+314,1,0); dial 9

MouseClick ("left",$position[0] + 354,$position[1]+262,1,0); dial 2

MouseClick ("left",$position[0] + 320,$position[1]+288,1,0); dial 4

MouseClick ("left",$position[0] + 354,$position[1]+314,1,0); dial 8

MouseClick ("left",$position[0] + 320,$position[1]+314,1,0); dial 7

MouseClick ("left",$position[0] + 354,$position[1]+342,1,0); dial 0

MouseClick ("left",$position[0] + 354,$position[1]+342,1,0); dial 0

MouseClick ("left",$position[0] + 354,$position[1]+342,1,0); dial 0

Link to comment
Share on other sites

Two more possibilities:

1. Just changing the option for MouseCoordMode to 2 gives you X/Y in client area (excludes title bar and border), and should always hit the mark.

2. Use AutoIT Info tool to get the control IDs or ClassNN name of the buttons and use ControlClick() to hit 'em.

:shocked:

ok, after some experimenting, now i know how to use mousecoordmode too. Thanks to PsaltyDS.

I cant use the second method because my dialer dont show any control IDs or ClassNN name, in the windowinfo tool, its blank. Thanks

my code

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

WinActivate ( "Digital Voice FlexiTalk")

MouseClick ("left" ,393,314,1,0)

Link to comment
Share on other sites

-------------PaulIA's script --------------------------------

#include <A3LWinAPI.au3>

Global $hWnd, $tRect, $tPoint, $iX, $iY

; Get the handle to the dialer window

$hWnd = WinGetHandle("Digital Voice FlexiTalk")

if $hWnd = 0 then _Lib_ShowError("Did not find Digital Voice FlexiTalk")

; Get the bounds of the dialer window

$tRect = _API_GetWindowRect($hWnd)

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

Thanks a lot everybody, I will be studying everything that is posted here.

Regarding PaulIA's script,

I want to have a feel of the functions and so I insert line by line one at a time but on the forth line $tRect = _API_GetWindowRect($hWnd), I got an error. The error msg I have attached here. I've read the help files which says that the function $tRect = _API_GetWindowRect($hWnd) is to Retrieves the dimensions of the bounding rectangle of the specified window.

So what must I do with the error?

Thanks

You must install the latest beta version of AutoIt.
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Two more possibilities:

........

2. Use AutoIT Info tool to get the control IDs or ClassNN name of the buttons and use ControlClick() to hit 'em.

.....

Hi,

I have the following code which is suppose to click the "save" button but it is not clicking anything at all. The "save as" window remains open. What have I miss, what must I do to click the 'save' button? I am using the controlclick command.

I have attach the pictures and the code and the 'Active window info' below.

What am I to do if I want to have better control by adding the ClassNameNN into the control click command. this is what I did but its wrong:- ControlClick ("Save As","FolderView",1[button2],1)

Thanks

---------------- code ---------------------------

$counter = 1

While $counter <=3

;MsgBox(0, "Value of $counter is:", $counter)

Run ("D:\Program Files\Prescient Systems\GOTCHA! 3.0\gotcha32.exe")

WinWaitActive("GOTCHA!")

WinClose ( "GOTCHA! - Creative WebCam NX (VFW)")

If WinActive ("GOTCHA!", "Do you wish to save the video buffer?") Then

ControlClick ("GOTCHA!","Do you wish to save the video buffer?",7,1)

ControlClick ("Save As","FolderView",1,1)

EndIf

$counter = $counter + 1

WEnd

----------- end of code -----------------------------

------------autoIT v3 active window info ------------------

>>>>>>>>>>>> Window Details <<<<<<<<<<<<<

Title: Save As

Class: #32770

Size: X: 518 Y: 178 W: 428 H: 266

>>>>>>>>>>> Mouse Details <<<<<<<<<<<

Screen: X: 894 Y: 389

Cursor ID: 2

>>>>>>>>>>> Pixel Color Under Mouse <<<<<<<<<<<

RGB: Hex: 0x000000 Dec: 0

>>>>>>>>>>> Control Under Mouse <<<<<<<<<<<

Size: X: 333 Y: 179 W: 75 H: 23

Control ID: 1

ClassNameNN: Button2

Text: &Save

Style: 0x50010001

ExStyle: 0x00000004

>>>>>>>>>>> Status Bar Text <<<<<<<<<<<

>>>>>>>>>>> Visible Window Text <<<<<<<<<<<

Save &in:

Gotch file

FolderView

File &name:

041507_134730.mv2

Save as &type:

GOTCHA files (*.mv2)

&Save

Cancel

>>>>>>>>>>> Hidden Window Text <<<<<<<<<<<

Open as &read-only

&Help

post-22053-1176616949_thumb.jpg

Link to comment
Share on other sites

When you use the ClassNameNN it is given as a string. The button parameter is also a string (i.e. "Left") and is not required at all if you want the default single click with the left button. See the help file on ControlClick(). Either of the following should have worked:

; With ClassNameNN
ControlClick ("Save As","FolderView","Button2")

; Or, with ControlID
ControlClick ("Save As","FolderView",1)oÝ÷ Øêí¢è¾'^jYmêZ­©µêìjëh×6; With ClassNameNN
ControlClick ("Save As","FolderView","Button2","Left",1)

; Or, with ControlID
ControlClick ("Save As","FolderView",1,"Left",1)

:shocked:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...