Kovacic

Mouse coordinates vs. window location

4 posts in this topic

Good morning.. I wrote a function but I am not sure if it is correct because my brain is fried.. I am using GDIPlus images as buttons [https://www.autoitscript.com/forum/topic/179132-gdiplus-png-manipulation-not-sure-how-to], hence they have no control ID, and cant be used as buttons any other way that I have found. Because of this, I am trying to make this function return true if the mouse is clicked within a box of coordinates. If someone could, take a look and see if my math is correct here:

 

#cs
Usage:_IsInsideOf

Use MouseGetPos() to get the mouse click with AutoItSetOption("MouseCoordMode", 0)

$coord_x, X location of mouse click 
$Coord_y, Y location of the mouse click
$Loc_X,    Left portion of box to check
$Loc_y,    Top portion of box to check
$Siz_x,    Height of box
$Siz_y     Width of box
#ce

 

Func _IsInsideOf($coord_x,$Coord_y,$Loc_X,$Loc_y,$Siz_x,$Siz_y)
if $coord_x > $Loc_X AND $coord_x < $Loc_X + $Siz_x AND $coord_y > $Loc_y AND $coord_y < $Loc_y + $Siz_y then 
return true
else
return false
endif
endfunc

 

Please take a look and let me know if this looks correct, or you know a simpler way. Thanks in advance!!


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I think it is good. Here is code to test with

Global $aPoints[10][2]=[[10,10], [10,45], [300, 23], [112,112], [345,87], [100,234], [22,54], [70,70], [33,33], [220,200]]
Global $aRectangle1[4]=[0,0,300,300], $aRectangle2[4]=[220, 113, 370,320] ;x, y, width, height
For $i=0 To 9
    $bTest1=_IsInsideOf($aPoints[$i][0], $aPoints[$i][1], $aRectangle1[0], $aRectangle1[1], $aRectangle1[2], $aRectangle1[3])
    ConsoleWrite("Is (" & $aPoints[$i][0] & ", " & $aPoints[$i][1] & ") in Rect1:" & $bTest1 & @CRLF)
    $bTest2=_IsInsideOf($aPoints[$i][0], $aPoints[$i][1], $aRectangle2[0], $aRectangle2[1], $aRectangle2[2], $aRectangle2[3])
    ConsoleWrite("Is (" & $aPoints[$i][0] & ", " & $aPoints[$i][1] & " in Rect1:" & $bTest2 & @CRLF)
Next

There is also a function _WinAPI_PtInRectEx()

Edited by ahmet
Mentioned _WinAPI_PtInRectEx()

Share this post


Link to post
Share on other sites

Try

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

An example can be found here.

Share this post


Link to post
Share on other sites

Is the application in which you are using stationary - always in the same spot?

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