Jump to content

Coordinates issue when using script on different PC


jben
 Share

Recommended Posts

Hi,

I'm new here and just recently downloaded AutoIT to help with automation of installation software (gets a bit repetitive as an administrator).

Anyways I have been playing with AutoIT and managed to get a little script working that moves a mouse cursor and clicks buttons. However I have an issue with coordinates. When I run the script on a different resolution PC the coordinates change, hence the mouse cursor is not in the correct place to click the button.

Code is currently like the following (minus the shellexecute as thats an obvious factor):

controlclick ("setup", "@next">",1)

mouseclick ("Button1",736,638,1,20)

mouseclick ("main")

From what I can understand the 736,638 coordinates are the issue with the code. I have used Window Info tool to obtain this data. Is there any way I can get this working, not sure how?

Many thanks

Edited by jben
Link to comment
Share on other sites

I recommend spending a little time running through the Autoit123 tutorial program list in the links in my signature.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

  • Moderators

look at the Opt("MouseCoordMode", N) options, 2 is for Client, those coords will always be the same on each computer regardless of screen resolution settings.

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

look at the Opt("MouseCoordMode", N) options, 2 is for Client, those coords will always be the same on each computer regardless of screen resolution settings.

Been reading the documentation. But I can't work out where to put the 2. Should that just replace the 1's in my code?.

Or do I need to declare this mousecoordmode.

Thanks

Link to comment
Share on other sites

Or do I need to declare this mousecoordmode.

Yes , just declare Opt("MouseCoordMode", 2) at the start of your script and any subsequent calls that use mouse coOrds will use them relative to the Client window , instead of to the Entire desktop.

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

Link to comment
Share on other sites

anyone got any ideas of what i'm doing wrong. I've Declared Opt("MouseCoordMode", 2) but cant work out how I should set the mouseclick event as I currently have predefined coords which I presume need to be removed.

Or do I just set the current coords to the coords in the application?

Edited by jben
Link to comment
Share on other sites

I see, so rather than using my current coords I should use the coords that are relevant to the GUI and then the coords will match up regardless of the resolution of the entire desktop?. (Providing that I declare mousecoordmode.)

I used windows info tool originally to obtain the coords but I guess I must have used the desktop coords and not the GUI, hence the mousecoordmode is not working. Can't check now as the code is at work but will look in the morning.

Cheers

Edited by jben
Link to comment
Share on other sites

If you use the AutoIt v3 Window Info tool, on the Control Tab, it will tell you the Position of the button realative to the GUI.

Perhaps we are using different versions of the AutoIt v3 Window Info tool, 'cuz my version only shows ControlClick Coords on the tab named Control and they are not with respect to the Client area of the highlighted window.

I think that jben should stick with the mouse position coordinates displayed within the AutoIt v3 Window Info tool, on the tab named "Mouse". Those can be changed to display coordinates with respect to screen, window or client by using the Options menu. Select Options,

Coord Mode, the client (in this case).

That said, I find it easier to use a little script to help out with such tasks:

AutoItSetOption("MouseCoordMode", 2)
AutoItSetOption("TrayIconDebug", 1)

HotKeySet("{PAUSE}", "Terminate")

While 1
    $pos = MouseGetPos()
    ToolTip("Client X: " & $pos[0] & ", " & "Window Y: " & $pos[1] & " Pause2exit")
    Sleep(10)
WEnd

Func Terminate()
    ClipPut('MouseClick("left",' & $pos[0] & ',' & $pos[1] & ',1,1)')
    Exit
EndFunc   ;==>Terminate
Run the script above

click on the window of interest to bring it into focus - if need be

place your mouse over the coordinates that you wish to click

press the pause key to exit the little script above

Now just go to the code of the main script that you are writing and and paste the info that is in the Windows clipboard.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Ahh. Just downloading AutoIT for home use (previously only had it available at work) and I discovered the options menu and chose Client. It seems like the coords of the button in my application stays the same now, regardless of whether i move the application box to any part of the screen.

I guess thats the idea?. Will try tommorow.

Link to comment
Share on other sites

Hi,

Thanks for you replys. I have obtained the coords now that are relevant to the GUI but the program doesn't seem to work. It just seems to move the mouse towards the top of the screen and all over the place.

Code is as follows:

opt("mousecoordmode",2)

controlclick("setup","@next",1)

mouseclick ("button1",339,20,1,20)

mouseclick ("main")

So i'm fairly stuck as I don't know why its doing this. I tried the script and used them coords and also tried the win info tool in client mode.

Anyone know what I could be doing wrong?. Thanks

Link to comment
Share on other sites

Sorry to hear that you are having problems - hang in there.

It appears that you skipped the controlID parameter in this line of code...

ControlClick("setup", "@next", 1)

ControlClick ( "title", "text", controlID, button, clicks, x, y)

...Is "1" the number of clicks that you want? If so, then you would either need to specify a controlID or use empty quotes (or empty double quotes) to give AutoIt something for that parameter (parm). And give it something for the button to click (right/left/middle). So, you cannot skip parms:

ControlClick("setup", "@next", "", "", 1)

Also, did the AutoIt Window Info tool really indicate @next or did it show &Next...

...it matters.

You coded a line like this: mouseclick ("button1",339,20,1,20)

The help file states that your options for the button parm are:

The button to click: "left", "right", "middle", "main", "menu", "primary", "secondary".

"button1" may work for you - it does not for me.

See my PM to you for more info.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

I managed to get it working in the end.

I got your PM and now im debating on what to do next. I like the idea of the mouse movements but maybe I need to really consider this.

As it stands i've got it to work. But whichever way I go I will then have a problem in Visual Basic.

Now this may be the wrong place to post. But ideally I will want to create a few scripts that install different applications and then have a command button in VB that installs all of these applications and a command button that allows for custom installation.

I can code all of this fine in VB. The only issue I would have is getting the VB code to wait for the current installation to finish before starting the next installation. I have posted this is a VB forum aswell in the hope that someone has an idea.

Thanks for all your replys.

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...