ags911 Posted December 18, 2013 Share Posted December 18, 2013 (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 December 18, 2013 by ags911 Link to comment Share on other sites More sharing options...
jdelaney Posted December 18, 2013 Share Posted December 18, 2013 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. Link to comment Share on other sites More sharing options...
ags911 Posted December 18, 2013 Author Share Posted December 18, 2013 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. Link to comment Share on other sites More sharing options...
jdelaney Posted December 18, 2013 Share Posted December 18, 2013 (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 December 18, 2013 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. Link to comment Share on other sites More sharing options...
ags911 Posted December 18, 2013 Author Share Posted December 18, 2013 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? Link to comment Share on other sites More sharing options...
ags911 Posted December 19, 2013 Author Share Posted December 19, 2013 Anyone? Link to comment Share on other sites More sharing options...
martin Posted December 20, 2013 Share Posted December 20, 2013 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. Link to comment Share on other sites More sharing options...
jdelaney Posted December 20, 2013 Share Posted December 20, 2013 (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 December 20, 2013 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. Link to comment Share on other sites More sharing options...
ags911 Posted December 21, 2013 Author Share Posted December 21, 2013 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? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 21, 2013 Moderators Share Posted December 21, 2013 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. 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts