# Converting x,y Positions To Different Resolution

## Recommended Posts

I made a function to convert x and y positions to different resolutions. My mom helped me with the equation so i don't know if it will work exactly. I keep getting decimals, so you might need to roud or take off the decimals along with the numbers. Tell me what ya think. It grabs the resolution of the current window and converts your x and y position. There were 2 different equations, so there are 2 different UDF's.

```Func ConvertX(\$Number)
\$Resolution = WinGetClientSize("")
\$PosX = \$Number * \$Resolution[0]/800
Return \$PosX
EndFunc

Func ConvertY(\$Number)
\$Resolution = WinGetClientSize("")
\$PosY = \$Number * \$Resolution[1]/600
Return \$PosY
EndFunc```

Hope ya like it.

--Edit--

Forgot to tell you the smallest Resolution it works with is 800x600!

Edited by =sinister=

##### Share on other sites

From this topic:

```; converts coords (x,y) in (a,b ) screen resolution to (c,d) screen resolution
Func _ConvertCoords( \$x, \$y, \$a, \$b, \$c = @DesktopWidth, \$d = @DesktopHeight )
Local \$ret[2] = [( \$c * \$x ) / \$a, ( \$d * \$y ) / \$b]
Return \$ret
EndFunc```

Hope it helps!

Edited by erifash

##### Share on other sites

I tried yours, and I still get decimals. I think rouding may help? Any ideas?

##### Share on other sites

That's no theory. That's basic(!) math.

##### Share on other sites

I tried yours, and I still get decimals. I think rouding may help? Any ideas?

Try the help file. AutoIt has a Round() function.

##### Share on other sites

works good enough for me

"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

##### Share on other sites

Int(\$x), Int(\$y) will return only the integer portions of the numbers. This is a simple way to get integers.

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

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...