# Using GetMousePos for calculating a MouseClick

## Recommended Posts

Hello There!

I've encountered a small issue i just cant seem to program my way out of...

What im doing is:        ;or rather, what im trying to do is
Pixelsearch for a color, within a part of my screen,
If color is present, i will rightclick it, for a menu to appear,
in which i want to Leftclick an option. Simplicity itself.

The issue is that because this menu appears in different parts of my screen, its complicated to select the option i want to click.
There is no special color to it, and i cannot define the area in which to click, because the menu appears different places.
The only thing that is in common for the menu is that the Leftclick needs to be (lets say) 30pixels below the rightclick

.

What can be done,  but seemingly not by me, is to get the coordinates of the rightclick, and use them as the "starting point" from where the coordinates for the leftclick will be.
(Not sure if that makes sence, but maybe the code below will help you understand)

You guys like example codes, so therefore i will give it my best shot, and hope it proves usefull

\$pos = Pixelsearch(200, 400, 200, 400, 0xFFFFFF)        ;This color is what i need to rightclick to bring up the menu
If not @Error then                                                               ;If the color is present
(Mouseclick("Right", \$pos[0], \$pos[1], 1, 1)                   ;Rightclick it, to bring up menu

;Here comes the part i cannot get to work
\$x = MousegetPos(X)                                                          ;To get the Coordinate "X", so we can calculated with it for the position of the leftclick
\$y = MousegetPos(Y)                                                           ; To get the Coordinate "Y", so that can be calculated with for the position of the leftclick

MouseClick("Left", \$x[0], \$y-30[1], 1, 1)                         ;This was supposed to give me a leftclick that is 30pixels below the rightclick.

(The MouseGetPos(X), may seem as a waste of space in this example, but in my script i will need both.
Im only using one in the example, mainly so that i wont confuse myself, but also to make it easier to digest for you guys
)

I have not been able to find any topic that covers this, but my apologies if such a topic already exist in the forums.

Maybe while im at it, can i ask,   what good does the [0] and [1] do, when using a "\$variable" as coordinate?

- DiveHigh

##### Share on other sites

\$a = MouseGetPos()
MouseClick("Left",\$a[0],\$a[1]-30)

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
##### Share on other sites

To anyone else that might find this useful i did some more test.

if you search for a color, and want to click it, but maybe with more randomized position of the click, then you can do:

\$pos = Pixelsearch(200, 400, 200, 400, 0xFFFFFF)
If not @Error then
MouseClick
("Left", \$pos[0]
+Random(-10,10), \$pos[1]+Random(-10,10), 1, 1)

[+Random(-10,10)  = this is +/- 10 pixels within the area which the color was found]

Have Fun!
- DiveHigh

##### Share on other sites

Just out of curiosity: Which program do you try to automate with this script?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
WebDriver - Wiki

##### Share on other sites

@water: may be a browser game

##### Share on other sites

• 3 weeks later...

This was used for a project in my class where we had a week to "create intelligence"..

## Create an account

Register a new account

• ### Similar Content

• #### Script that uses a lot of mouse click coordinates

By TheAutomator,

• 9 replies
• 2,481 views
• #### Clicking button or sending shortcut to (stubbern) Windows - (Moved)

By dejhost,

• 13 replies
• 1,408 views
• #### Counter skipping 0

By Maffiagang,

• 5 replies
• 921 views
• #### simple date calculator

By nacerbaaziz,

• 4 replies
• 1,603 views
• #### Mouse click in text box

By Rskm,

• 8 replies
• 2,780 views
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...