Sign in to follow this  
Followers 0
ags911

Script that detects aspect ratio automatically

10 posts in this topic

#1 ·  Posted (edited)

H guys, I have a script that uses mouse clicks at different positions on the screen but I realised every UI changes depeding on aspect ratio. I have solved the problem of scaling to different resolutions by using percentages @desktopwidth @desktopheight so now the main issue is making one script that automatically detects aspect ratio like this:

CoordSwitch($coordx0, $coordy0)

Func CoordSwitch($OriginalXCoord, $OriginalYCoord)
    Local $AdjustedXCoord, $AdjustedYCoord, $DH, $DW

    $DW = @DesktopWidth
    $DH = @DesktopHeight
    
    Switch $DW & 'x' & $DH
        Case "1920x1080", "1600x900", "1366x768", "1360x768", "1280x720" ;16:9
            $AdjustedXCoord = ($DW / 1920) * $OriginalXCoord
            $AdjustedYCoord = ($DH / 1080) * $OriginalYCoord
            MouseClick("Left", $AdjustedXCoord, $AdjustedYCoord, 1)
        Case "1680x1050", "1440x900", "1280x800" ; 16:10
            $AdjustedXCoord = ($DW / 1680) * $OriginalXCoord
            $AdjustedYCoord = ($DH / 1050) * $OriginalYCoord
            MouseClick("Left", $AdjustedXCoord, $AdjustedYCoord, 1)
        Case "1400x1050", "1360x1024", "1280x960", "1152x864", "1024x768", "800x600" ; 4:3
            $AdjustedXCoord = ($DW / 1400) * $OriginalXCoord
            $AdjustedYCoord = ($DH / 1050) * $OriginalYCoord
            MouseClick("Left", $AdjustedXCoord, $AdjustedYCoord, 1)
        Case Else
            MsgBox(0, '???', $DW & 'x' & $DH)
    EndSwitch
EndFunc

I have written 3 different scripts for each aspect ratio 4:3, 16:9 and 16:10 but I would like to include all the data in one script so it can automatically change probably based on IF statements.

This is my code so far. (4:3 Aspect Ratio) The mouse clicks are the main data, I also have the coordinates for 16:9 and 16:10 so please ask if you need those also thanks!

Global $sHeight = @DesktopHeight
Global $sWidth = @DesktopWidth
Global $UnPaused
HotKeySet("+1","_TogglePause") ; Press Shift+1 to start script
HotKeySet("+2", "_Terminate") ; Press Shift+2 to terminate script
    
    MsgBox(64, "Welcome!")

While 1 ; Loop 1
Sleep(100) ; Waiting for function call. Pressing the Start hotkey ends this loop
ToolTip('Paused. Press SHIFT+1 to resume/pause or SHIFT+2 to terminate.',0,0)
WEnd

Func _TogglePause()
   ToolTip('Started. Press SHIFT+1 to pause or SHIFT+2 to terminate.',0,0)
   $UnPaused = NOT $UnPaused
While $UnPaused ; Loop 2
ToolTip("1")
MouseClick("Left", @DesktopWidth *0.931, @DesktopHeight *0.846, 1, 10)

ToolTip("2")
MouseClick("Left", @DesktopWidth *0.0771, @DesktopHeight *0.723, 1, 20)

ToolTip("3")
MouseClick("Left", @DesktopWidth *0.622, @DesktopHeight *0.515, 2, 20)

ToolTip("4")
MouseClick("Left", @DesktopWidth *0.463, @DesktopHeight *0.606, 2, 20)

ToolTip("5")
MouseClick("Left", @DesktopWidth *0.273, @DesktopHeight *0.584, 1, 20)

ToolTip("6")
MouseClick("Left", @DesktopWidth *0.506, @DesktopHeight *0.608, 1, 20)

WEnd
EndFunc


Func _Terminate()
    If MsgBox(4, 'Do you want to exit?', 'Click Yes to exit, or No to continue') = 6 Then Exit
EndFunc   ;==>_Pause

 

Edited by ags911

Share this post


Link to post
Share on other sites



Not answering your question dirctly:

Rather than relative coords, you should look into control* functions

Such as controlclick, WinGetHandle, ControlGetHandle

What is the point of your script?


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Is my script not using control*functions already? ControlClick ( "title", "text", controlID [, button [, clicks [, x [, y]]]] ). Mine is in percentages though to keep it compatible with different screen resolutions in the same aspect ratio so far. My script is used for automatically clicking buttons inside a web app continuously and uses shift+1 to pause and shift+2 to exit.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You are using mouseclick, which are relative XY coords...controlclick clicks the matching control, regardless of the x/y...aspect ratios won't matter.

If it's a web app, use the IE.au3, or FF.au3 files.

Then you can click on specific span/links, which again, would NOT be related to XY.

If you use relative coords, there is 99% of the times, a better way to do it.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

It is a javascript/flash player based web app. Will that work with control script or not since I don't think they are windows based buttons?

Share this post


Link to post
Share on other sites

Anyone?

Share this post


Link to post
Share on other sites

It is incorrect to say that MouseClick uses relative coordinates (jdelaney). The X,Y coordinates are interpreted according to the MouseCoordMode setting.

If the buttons are drawn rather than being actual controls then Control.... functions won't be any help.

 

I would expect that if the browser window aspect ratio changed, whether because of the screen dimensions or because someone resized it, then the positions of the buttons, images and text will be difficult to predict. So although I know next to nothing about the IE functions, and nothing about the web page you are interested in, I would expect that as jdelaney says, the IE functions would be the most reliable way to deal with your problem.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

It is incorrect to say that MouseClick uses relative coordinates (jdelaney). The X,Y coordinates are interpreted according to the MouseCoordMode setting.

If the buttons are drawn rather than being actual controls then Control.... functions won't be any help.

 

I would expect that if the browser window aspect ratio changed, whether because of the screen dimensions or because someone resized it, then the positions of the buttons, images and text will be difficult to predict. So although I know next to nothing about the IE functions, and nothing about the web page you are interested in, I would expect that as jdelaney says, the IE functions would be the most reliable way to deal with your problem.

Yes, i was stating in general.  Regardless of the option you select, it will be relative within those bounds.  I was trying to tell him of a direct, non relative route.  I was unaware that the gui was painted, until one of the more recent posts.  As most painted applications I know of are games, I stopped responding.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

It is incorrect to say that MouseClick uses relative coordinates (jdelaney). The X,Y coordinates are interpreted according to the MouseCoordMode setting.

If the buttons are drawn rather than being actual controls then Control.... functions won't be any help.

 

I would expect that if the browser window aspect ratio changed, whether because of the screen dimensions or because someone resized it, then the positions of the buttons, images and text will be difficult to predict. So although I know next to nothing about the IE functions, and nothing about the web page you are interested in, I would expect that as jdelaney says, the IE functions would be the most reliable way to deal with your problem.

 

Yes, i was stating in general.  Regardless of the option you select, it will be relative within those bounds.  I was trying to tell him of a direct, non relative route.  I was unaware that the gui was painted, until one of the more recent posts.  As most painted applications I know of are games, I stopped responding.

 Hi thanks for the feedback, the website in question is http://www.easports.com/uk/fifa/football-club/ultimate-team but I don't know if you have any access to it but you can see it in action on YouTube. The tool you suggested doesn't detect the buttons on that flash player any ideas?

Share this post


Link to post
Share on other sites

ags911,

That site appears to be a game. If so then you appear to have missed the Forum rules on your way in. Please read them now (there is also a link at bottom right of each page) - particularly the bit about not discussing game automation - and then you will understand why this thread will now be locked. :naughty:

Of course if it is not a game then by all means PM me (with an explanation) and the thread will be reopened. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0