Jump to content

Mouse X&Y Between Functions


Recommended Posts

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

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

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

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to post
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (NEW 2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

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

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...