Jump to content

coverting X,Y coords for various screen resolutions


ssubirias3
 Share

Recommended Posts

Hi, I'm new to the forums and autoit. I'm not a programmer just another leech who looks for scripts that may help in the current end goal. Though I am trying to learn this stuff myself.... sometimes its easier to search for the answer and seeking out the vets.

PROBLEM 1:

I'm putting together a simple script that uses a lot of WinMove and MouseClick commands, but when I use the same script on different computers with different resolutions, I get different results when the MouseClick commands are sent to flash websites. MouseClicks to non-flash websites work fine regardless of the resolution.

So end goal? To find either a script or program that will allow me to enter a resolution and mouse X,Y values then upon clicking 'GO' the program magically provides the exact X,Y values for different resolutions (800x600, 1024x768, 1280x768, 1280x800). Then I can simply cut and past the text from the program into my scripts or include the script in each of my programs... if that makes sense.

btw, the solution of using Opt("MouseCoordMode",2) as recommended in the "different resolutions" thread does not work for me. Not sure why, maybe because I'm sending the mouseclick commands to a flash website?? Doesn't make sense to me why it would matter html or flash, but there seems to be a difference.

PROBLEM 2:

Once the X,Y coords are set it seems like I'm doing something wrong with the syntax of the MouseClick commands. I would think that MouseClick("left", $flashXYa) would work, but it doesn't process. Any suggestions?

Thanks in advance!

#cs /// Resolution test
Opt("MouseCoordMode",0)
$res=@DesktopWidth & " x " & @DesktopHeight
If $res="800 x 600" then
    $flashXYa="123,165"
    $flashXYb="123, 288"
    $flashXYc="260, 349"    
Elseif $res="1024 x 768" then
    $flashXYa=""
    $flashXYb=""
    $flashXYc=""
ElseIf $res="1280 x 768" then
    $flashXYa=""
    $flashXYb=""
    $flashXYc=""
ElseIf $res="1280 x 800" then 
    $flashXYa="174,175"
    $flashXYb="174, 298"
    $flashXYc="312, 359"
EndIf
MouseClick("left", $flashXYa)
Sleep(3000)
MouseClick("left", $flashXYb)
#ce
Link to comment
Share on other sites

Hi, I'm new to the forums and autoit. I'm not a programmer just another leech who looks for scripts that may help in the current end goal. Though I am trying to learn this stuff myself.... sometimes its easier to search for the answer and seeking out the vets.

PROBLEM 1:

I'm putting together a simple script that uses a lot of WinMove and MouseClick commands, but when I use the same script on different computers with different resolutions, I get different results when the MouseClick commands are sent to flash websites. MouseClicks to non-flash websites work fine regardless of the resolution.

So end goal? To find either a script or program that will allow me to enter a resolution and mouse X,Y values then upon clicking 'GO' the program magically provides the exact X,Y values for different resolutions (800x600, 1024x768, 1280x768, 1280x800). Then I can simply cut and past the text from the program into my scripts or include the script in each of my programs... if that makes sense.

btw, the solution of using Opt("MouseCoordMode",2) as recommended in the "different resolutions" thread does not work for me. Not sure why, maybe because I'm sending the mouseclick commands to a flash website?? Doesn't make sense to me why it would matter html or flash, but there seems to be a difference.

PROBLEM 2:

Once the X,Y coords are set it seems like I'm doing something wrong with the syntax of the MouseClick commands. I would think that MouseClick("left", $flashXYa) would work, but it doesn't process. Any suggestions?

Thanks in advance!

#cs /// Resolution test
Opt("MouseCoordMode",0)
$res=@DesktopWidth & " x " & @DesktopHeight
If $res="800 x 600" then
    $flashXYa="123,165"
    $flashXYb="123, 288"
    $flashXYc="260, 349"    
Elseif $res="1024 x 768" then
    $flashXYa=""
    $flashXYb=""
    $flashXYc=""
ElseIf $res="1280 x 768" then
    $flashXYa=""
    $flashXYb=""
    $flashXYc=""
ElseIf $res="1280 x 800" then 
    $flashXYa="174,175"
    $flashXYb="174, 298"
    $flashXYc="312, 359"
EndIf
MouseClick("left", $flashXYa)
Sleep(3000)
MouseClick("left", $flashXYb)
#ce
Welcome to AutoIT! :)

A simple math fuction can do a convert for you:

$flashXa = 512, $flashYa = 256 ; Your intended coordinates on the original 800x600 desktop
_ConvertXY($flashXa, $flashYa) ; Convert proportionally to the actual desktop size
MouseClick("left", $flashXa, $flashYa) ; Use the new values to click

$flashXb = 300, $flashYb = 400
_ConvertXY($flashXb, $flashYb)
MouseClick("left", $flashXb, $flashYb)

; Fuction to convert screen coordinates
Func _ConvertXY(ByRef $Xin, ByRef $Yin)
     $Xin = Round( ($Xin / 800) * @DesktopWidth )
     $Yin = Round( ($Yin / 600) * @DesktopHeight )
EndFunc

Your MouseClick() functions require three parameters, per the help file: Button, X, and Y. See usage in example above.

:P

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks for the quick reply PsaltyDS! Sorry to be such an idiot about this, I did say I wasn't a programmer; right??? :)

Would your response then imply that I would need 1 Func_ConvertXY for each of the resolutions and the Round(($Xin...) and Round (($Yin...) would be 800x600, 1024x768, 1280x800... etc?

If my assumption is right... then the code would look like::

; /// Resolution test
Opt("MouseCoordMode",0)
$res=@DesktopWidth & " x " & @DesktopHeight
If $res="800 x 600" then   ;< /// assume 800x600 resolution
;        $flashXYa = "123, 165"
;        $flashXYb = "123, 288"
;
$flashXa = 123, $flashYa = 165 
$flashXb = 123, $flashYb = 288
_ConvertXY($flashXa, $flashYa) 
_ConvertXY($flashXb, $flashYb)
Func _ConvertXY(ByRef $Xin, ByRef $Yin)
     $Xin = Round( ($Xin / 800) * @DesktopWidth )
     $Yin = Round( ($Yin / 600) * @DesktopHeight )
EndFunc
ElseIf $res="1280 x 768" then   ;<-- /// assume 1280x800 resolution
_ConvertXY($flashXa, $flashYa) 
_ConvertXY($flashXb, $flashYb)
Func _ConvertXY(ByRef $Xin, ByRef $Yin)
     $Xin = Round( ($Xin / 1280) * @DesktopWidth )
     $Yin = Round( ($Yin / 800) * @DesktopHeight )
EndFunc
EndIf
MouseClick("left", $flashXa, $flashYa)
Sleep(3000)
MouseClick("left", $flashXb, $flashYb)
Edited by ssubirias3
Link to comment
Share on other sites

Thanks for the quick reply PsaltyDS! Sorry to be such an idiot about this, I did say I wasn't a programmer; right??? :)

Would your response then imply that I would need 1 Func_ConvertXY for each of the resolutions and the Round(($Xin...) and Round (($Yin...) would be 800x600, 1024x768, 1280x800... etc?

If my assumption is right... then the code would look like::

; /// Resolution test
Opt("MouseCoordMode",0)
$res=@DesktopWidth & " x " & @DesktopHeight
If $res="800 x 600" then   ;< /// assume 800x600 resolution
;        $flashXYa = "123, 165"
;        $flashXYb = "123, 288"
;
$flashXa = 123, $flashYa = 165 
$flashXb = 123, $flashYb = 288
_ConvertXY($flashXa, $flashYa) 
_ConvertXY($flashXb, $flashYb)
Func _ConvertXY(ByRef $Xin, ByRef $Yin)
     $Xin = Round( ($Xin / 800) * @DesktopWidth )
     $Yin = Round( ($Yin / 600) * @DesktopHeight )
EndFunc
ElseIf $res="1280 x 768" then   ;<-- /// assume 1280x800 resolution
_ConvertXY($flashXa, $flashYa) 
_ConvertXY($flashXb, $flashYb)
Func _ConvertXY(ByRef $Xin, ByRef $Yin)
     $Xin = Round( ($Xin / 1280) * @DesktopWidth )
     $Yin = Round( ($Yin / 800) * @DesktopHeight )
EndFunc
EndIf
MouseClick("left", $flashXa, $flashYa)
Sleep(3000)
MouseClick("left", $flashXb, $flashYb)
I don't think you need all that. When you code the script, pick a default desktop resolution (it's 800x600 in my example) and the math in the function will automatically proportion the x/y coordinates to whatever size the current desktop is (by using the @DesktopWidth and @DesktopHeight macros). You only need the one function to convert to any desktop size. The only thing hard-coded into the script is the default desktop size that you code your script on, because inside the _ConvertXY() function the default number is used to generate a proportional value that is then multiplied by the current desktop size.

All this may become moot -- you didn't say what this was for. If what you wanted was to be able to hit a coordinate inside a window, despite changing desktop size, you can change the default Opt("MouseCoordMode", 1) to Opt("MouseCoordMode", 0) and the coordinates will be realative to the active window, not the desktop.

So just to be sure we aren't going off on a wild tangent - what are you trying to click on?

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

... you can change the default Opt("MouseCoordMode", 1) to Opt("MouseCoordMode", 0) and the coordinates will be realative to the active window, not the desktop.

So just to be sure we aren't going off on a wild tangent - what are you trying to click on?

I already have the Opt("MouseCoordMode", 0) set at the top of my script and the MouseClick coords aren't sent to the "correct" location when testing on different computers with different resolutions _NOR_ on the same computer if the resolution is changed. Using Opt("MouseCoordMode", 2) did not work either despite using X,Y coords from WinInfo set to Client Mode. The X,Y coords I'm using with Opt("MouseCoordMode", 0) are from WinInfo set to Window Mode.

To your question of "what are you trying to click on?"... I'm sending the MouseClicks to an IE browser window that loads a flash website (www.subpennyradio.com). Here is the code that I'm trying to get to work on any computer that has IE installed on it regardless of resolution.

Also in SciTe Version 1.67 I get an syntax error with "$flashXa= 174, $flashYa= 175" ... hence the variables on two seperate lines verses one. Ideas why I'm getting the syntax error? The following code works fine if the resolution is set to 1280x800, but does not work if the resolution is changed to 800x600 on the same computer.

Thanks again!

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
; ///   XYa, XYb, XYc coords based on known good coords at 1280x800 resolution
$flashXa = 174
$flashYa = 175
_ConvertXY($flashXa, $flashYa)

$flashXb = 174
$flashYb = 298
_ConvertXY($flashXb, $flashYb)

$flashXc = 311
$flashYc = 359
_ConvertXY($flashXc, $flashYc)

; Fuction to convert screen coordinates
Func _ConvertXY(ByRef $Xin, ByRef $Yin)
     $Xin = Round( ($Xin / 1280) * @DesktopWidth )
     $Yin = Round( ($Yin / 800) * @DesktopHeight )
EndFunc
Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE http://www.subpennyradio.com")
WinWaitActive("SubPennyRadio: Smallcap & Penny Stock Talk Radio - Microsoft Internet Explorer", "Done")
WinMove("SubPennyRadio: Smallcap & Penny Stock Talk Radio - Microsoft Internet Explorer","",379,0,900,700)

MouseClick("left", $flashXa, $flashYa)
Sleep(3000)
MouseClick("left", $flashXb, $flashYb)
Send("{CTRLDOWN}")
MouseClick("left", $flashXc, $flashYc)
Send("{CTRLUP}")
Link to comment
Share on other sites

  • Moderators

When we report errors, we are usually up to date with the versions of each 1st and 3rd party program we are using....

http://www.autoitscript.com/autoit3/scite/downloads.php

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I already have the Opt("MouseCoordMode", 0) set at the top of my script and the MouseClick coords aren't sent to the "correct" location when testing on different computers with different resolutions _NOR_ on the same computer if the resolution is changed. Using Opt("MouseCoordMode", 2) did not work either despite using X,Y coords from WinInfo set to Client Mode. The X,Y coords I'm using with Opt("MouseCoordMode", 0) are from WinInfo set to Window Mode.

To your question of "what are you trying to click on?"... I'm sending the MouseClicks to an IE browser window that loads a flash website (www.subpennyradio.com). Here is the code that I'm trying to get to work on any computer that has IE installed on it regardless of resolution.

Also in SciTe Version 1.67 I get an syntax error with "$flashXa= 174, $flashYa= 175" ... hence the variables on two seperate lines verses one. Ideas why I'm getting the syntax error? The following code works fine if the resolution is set to 1280x800, but does not work if the resolution is changed to 800x600 on the same computer.

Thanks again!

Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
; ///   XYa, XYb, XYc coords based on known good coords at 1280x800 resolution
$flashXa = 174
$flashYa = 175
_ConvertXY($flashXa, $flashYa)

$flashXb = 174
$flashYb = 298
_ConvertXY($flashXb, $flashYb)

$flashXc = 311
$flashYc = 359
_ConvertXY($flashXc, $flashYc)

; Fuction to convert screen coordinates
Func _ConvertXY(ByRef $Xin, ByRef $Yin)
     $Xin = Round( ($Xin / 1280) * @DesktopWidth )
     $Yin = Round( ($Yin / 800) * @DesktopHeight )
EndFunc
Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE http://www.subpennyradio.com")
WinWaitActive("SubPennyRadio: Smallcap & Penny Stock Talk Radio - Microsoft Internet Explorer", "Done")
WinMove("SubPennyRadio: Smallcap & Penny Stock Talk Radio - Microsoft Internet Explorer","",379,0,900,700)

MouseClick("left", $flashXa, $flashYa)
Sleep(3000)
MouseClick("left", $flashXb, $flashYb)
Send("{CTRLDOWN}")
MouseClick("left", $flashXc, $flashYc)
Send("{CTRLUP}")

I wrote an installer for ColdFusion, where the installer windows have controls that are invisible to AutoIT, and it required clicking by coordinates. What I found was that the windows were drawn by pixel counts and the same x/y coordinates (relative to the ColdFusion window) did not change with the desktop setting. The window remains the same number of pixels in size, it just appears smaller or bigger. When you use the AutoIT Info tool, do you see the relative coordinates change with the desktop for the same point in the window?

I also notice you do not have standard 4:3 aspect ratio to the resolution you are using (1280x800). The standard 4:3 setting atthat resolution is 1280x1024. If the math is required, different aspect ratios of the screen would throw the results off, which can be corrected with a little more math, if those values are correct.

Another thing to consider is IE.au3 functions reading the web page to give you the exact dimensions of just the flash element on the page. Something I have no experience with, but many others on this board do. Using IE.au3 for bots in flash games is a common topic here, jut not interesting to me in particular.

:)

P.S. It would be usefull to get exact results from your experiment: Use AutoIT Info to get the exact (window or client area relative) coordinates required at, say, four different desktop resolutions. Post the X/Y and desktop size numbers used for all of them so we can see how they are mathematically related.

:P

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...