Timppa

Mouse X&Y Between Functions

4 posts in this topic

#1 ·  Posted (edited)

Hello!

I have tried to check if mouse is between certain pixels by this script:

Global $MousePosition = MouseGetPos()
Global $LocationX1 = 200
Global $LocationX2 = 300
Global $LocationY1 = 150
Global $LocationY2 = 600
Global $CheckX
Global $CheckY

If $MousePosition[0] = random($LocationX1, $LocationX2) Then
   ToolTip("Mouse X is at location.")
   $CheckX = 1
Else
   ToolTip("Mouse X is not at location.")
   $CheckX = 0
EndIf

If $MousePosition[1] = random($LocationY1, $LocationY2) Then
   ToolTip("Mouse Y is at location.")
   $CheckY = 1
Else
   ToolTip("Mouse Y is not at location.")
   $CheckY = 0
EndIf

If $CheckX == 1 And $CheckY == 1 Then
    ToolTip("Mouse X&Y is at location")
    Sleep(3000)
    Exit
EndIf

So it basicly just checks where my mouse is (between certain location), but when I think that using random(x,y) is incorrect.

So what I am asking is that is there any command like Between(x,y) because random just randomizes the numbers in it and that's why it won't work. Couldn't find this solution anywhere by google :(

 

Thanks in advance!

 

EDIT: When I execute this, it always says Mouse X is not at location and same for Y, even if the mouse is at the location.

Edited by Timppa

Share this post


Link to post
Share on other sites



Both coordinates form a rectangle. I assume that X1/Y1 is the upper left corner and X2/Y2 the lower right corner.
So you are looking for something like this:

Global $aMousePosition
Global $iLocationX1 = 200
Global $iLocationY1 = 150
Global $iLocationX2 = 300
Global $iLocationY2 = 600

While 1
    $aMousePosition = MouseGetPos()
    If $aMousePosition[0] < $iLocationX1 Or $aMousePosition[0] > $iLocationX2 Or $aMousePosition[1] < $iLocationY1 Or $aMousePosition[1] > $iLocationY2 Then
        ToolTip("Mouse is out of the area. X: " & $aMousePosition[0] & ", Y: " & $aMousePosition[1])
    Else
        ToolTip("Mouse is in the area. X: " & $aMousePosition[0] & ", Y: " & $aMousePosition[1])
    EndIf
    Sleep(50)
WEnd

 

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thank you! Works perfectly now :)

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

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