Sign in to follow this  
Followers 0

Detect Resolution and change coordinates using elseif statements

4 posts in this topic

I have a script that has to work on multiple resolutions but each resolution has slightly different co-ordinates due to automatic UI scaling. I have had to make separate files for each but would like to implement them all in one script. I have a similar program written for Java which uses else if statements to use different co-ordinates for each resolution after it has been detected. I'm not good with Java so I would like to implement this on AutoIt before later making a Java version.


This is a snippet of the autoit code I have.

ToolTip("1 - Search")
MouseClick("Left", @DesktopWidth *0.823, @DesktopHeight *0.925, 1, 25)

ToolTip("2 - Buy Now")
MouseClick("Left", @DesktopWidth *0.83, @DesktopHeight *0.798, 1, 27)

ToolTip("3 - OK")
MouseClick("Left", @DesktopWidth *0.555, @DesktopHeight *0.596, 1, 15)

ToolTip("4 - OK Clear Error")
MouseClick("Left", @DesktopWidth *0.49, @DesktopHeight *0.597, 1, 30)

ToolTip("5 - Back to Search")
MouseClick("Left", @DesktopWidth *0.161, @DesktopHeight *0.108, 1, 15)


This is a snippet of a java code I used.


private static void goToSearch(double maxX, double maxY, Robot bot) throws InterruptedException {

    int currentX = 0;

    int currentY = 0;

    if (maxX == 2650 && maxY == 1440) {

        currentX = 734;

        currentY = 1316;

    } else if (maxX == 1920 && maxY == 1200) {

        currentX = 551;

        currentY = 1096;

    } else if (maxX == 1920 && maxY == 1080) {

        currentX = 551;

        currentY = 1042;

    } else if (maxX == 1680 && maxY == 1050) {

        currentX = 482;

        currentY = 959;

    } else if (maxX == 1440 && maxY == 900) {

        currentX = 413;

        currentY = 822;

    } else if (maxX == 1366 && maxY == 768) {

        currentX = 392;

        currentY = 741;

    } else if (maxX == 1280 && maxY == 800) {

        currentX = 367;

        currentY = 731;

Share this post

Link to post
Share on other sites

@ags911 can you please explain what your end goal is with the AutoIt script? There is almost certainly a much better way of accomplishing what you're after than with unreliable MouseClicks based on screen resolution (as you are finding out).

√-1 2^3 ∑ π, and it was delicious!

Share this post

Link to post
Share on other sites

Thanks for the reply. Please find the file attached. The mouse interacts with different elements onscreen of an online game via google chrome. Do you have anything in mind? The elements change and scale slightly for each resolution so I've had to compile a different script for each. The idea was that I could put everything into one simple script that detects the monitor resolution and automatically uses the script for that resolution.

PAB Forum - 1920 x 1080 - Speed (Slow).au3

Share this post

Link to post
Share on other sites

Unfortunately, you seem to have missed the forum rules during your time here. Please read them now, especially the part on game automation, and you will see why this thread is now locked.

√-1 2^3 ∑ π, and it was delicious!

Share this post

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

  • Similar Content

    • Simpel
      By Simpel
      I'm trying to do a teletext viewer. Here is my code:
      #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <ButtonConstants.au3> Local $sURL = "" Local $oIE = ObjCreate("Shell.Explorer.2") GUICreate("NDR Text", 494, 601) GUICtrlCreateObj($oIE, 0, 0, 513, 574) Local $idLabel_Number = GUICtrlCreateInput("", 2, 574, 60, 25, $ES_CENTER) GUICtrlSetFont(-1, 14) GUICtrlSetLimit(-1, 3) GUICtrlSetState(-1, $GUI_FOCUS) Local $idButton_OK = GUICtrlCreateButton("OK", 64, 574, 60, 25, $BS_DEFPUSHBUTTON) GUICtrlSetFont(-1, 14) $oIE.navigate($sURL) GUISetState(@SW_SHOW) ;Show GUI While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idButton_OK If GUICtrlRead($idLabel_Number) >= 100 And GUICtrlRead($idLabel_Number) < 900 Then $oIE.navigate("" & GUICtrlRead($idLabel_Number) & "_01.htm") EndIf GUICtrlSetState($idLabel_Number, $GUI_FOCUS) EndSwitch WEnd GUIDelete() It works but it doesn't look so good as shown direct in the InternetExplorer 11. Differences seen in the images I attached. I want to have the look like in the IE (first picture).
      How to change my code?
      Regards, Conrad

    • Psyllex
      By Psyllex
      I have a super simple login screen I'm trying to access that is written in java.  My java testing tools can't access the login screen because it's a modal window.  So I figured I'd see if AutoIt can manipulate 'something' on it.  I can enter text within the text boxes for user name and password.  But I can't see to click on the login button.  I've tried just tabbing to it and hitting the enter key (as I really wouldn't have to be completely interacting with the frame).  But that didn't work.  I was hoping to throw it some coordinates and just double click in that relative area, but when I get the whole " ==> Subscript used on non-accessible variable.:" when I attempt to use ControlGetPos() I'm assuming because it can't truly interact with the Java frame.  So I'm kind of stuck here...can't use AutoIt, can't use a Java automation testing tool to do this due to the modal issues.  Does anyone have any ideas?  My code is below though I think it's less to do with code and more what AutoIt can and can't do.
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Local $hWnd = WinActivate("[CLASS:sunawtframe]", "Login") Local $aPos = ControlGetPos($hWnd, "[CLASS:SUNAWTFRAME]", "Login") Local $myXPos = $aPos[0] + 420 Local $myYPos = $aPos[1] + 270 Send("guest") Send("{TAB}") Send("guest") Send("{TAB}") ;Tried Control Click it failed ControlClick($hWnd, "", "Login") ;Tried Mouse Click and that failed MouseClick("Left", $myXPos, $myYPos, 2)  
      Thanks for any help!
    • Docfxit
      By Docfxit
      This script created by Varian is getting an error saying Obfuscator support has been discontinued and replaced by Au3Stripper.
      He said:
      To help you with the coordinates, use this script and browse over the button or area that you wish to be clicked. Exit the script by pressing the Escape key. The information displayed on the exiting message box will be copied to the clipboard for you to paste into a text editor so that you can use it. Just make sure that you use the correct MouseCoord option (window/client). you should also make sure that the window size remains constant...this can be handled using the WinMove() function.
      Has anyone converted it to Au3Stripper or can you convert it?
      #region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=\\TEST-PC\D$\Icons\Intellipoint-010.ico #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Fileversion= #AutoIt3Wrapper_Res_LegalCopyright=Created by Varian L.Styles #AutoIt3Wrapper_Run_AU3Check=n #AutoIt3Wrapper_Run_Obfuscator=y #Obfuscator_Parameters=/striponly #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** Opt('PixelCoordMode', 2) Opt('MouseCoordMode', 2) Opt('TrayIconDebug', 1) Opt('TrayAutoPause', 0) #include <Misc.au3> _Singleton(@ScriptName, 0) ProcessSetPriority(@AutoItPID, 0) Global $wPos, $mPos, $mClientPos, $mWindowPos, $Text, $wTitle, $Color HotKeySet('{ESC}', '_Quit') While 1 Mouse_Coords() ;Sleep(10) WEnd Func _Quit() ToolTip('') $Text &= 'Mouse Position/Desktop: ' & $$mPos[0] & ',' & $$mPos[1] & @CRLF $Text &= 'Mouse Position/Window: ' & $mWindowPos[0] & ',' & $mWindowPos[1] & @CRLF $Text &= 'Mouse Position/Client: ' & $mClientPos[0] & ',' & $mClientPos[1] & @CRLF $wPos = WinGetPos('[ACTIVE]', '') $wTitle = StringLeft(WinGetTitle('[ACTIVE]', ''), 15) $Text &= '"' & $wTitle & '" Top-Left Coords: ' & $wPos[0] & ',' & $wPos[1] & @CRLF $Text &= '"' & $wTitle & '" Window Size: ' & $wPos[2] & ',' & $wPos[3] & @CRLF $Text &= 'Color: ' & Hex(PixelGetColor($mClientPos[0], $mClientPos[1]), 6) ClipPut($Text) MsgBox(0, 'Mouse Position Results', $Text) Exit EndFunc ;==>_Quit Func Mouse_Coords() Local $String Opt('MouseCoordMode', 1) $mPos = MouseGetPos() Opt('MouseCoordMode', 0) $mWindowPos = MouseGetPos() Opt('MouseCoordMode', 2) $mClientPos = MouseGetPos() $Color = 'Hex Color: ' & Hex(PixelGetColor($mClientPos[0], $mClientPos[1]), 6) $String &= 'Window Title: ' & StringLeft(WinGetTiTle('[ACTIVE]'), 25) & @LF $String &= 'Desktop X: ' & $mPos[0] & ' Y: ' & $mPos[1] & @LF $String &= 'Window X: ' & $mWindowPos[0] & ' Y: ' & $mWindowPos[1] & @LF $String &= 'Client X: ' & $mClientPos[0] & ' Y: ' & $mClientPos[1] & @LF ToolTip($String & $Color) EndFunc ;==>Mouse_Coords Thanks,
    • Ubermensch
      By Ubermensch
      I am currently trying to automatically click the "Yes" button in the ActiveX prompt/popup message after opening the IE (html).
      At 1st, I encounter the "Allow Blocked Content". I already resolve it just by changing settings in the IE Options. But after resolving the "Allow Blocked Content", there's a popup message appear.
      I have attached the ActiveX Prompt.
      Here is the 1st code that I try to use.
      #include <IE.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> _IECreate("C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\sampleAWD10.html",0,1,0) Local $oIE = _IEAttach("", "instance", 1) _IELoadWait($oIE) AdlibRegister("_ActiveXRun",250) Local $oLastName = _IEGetObjByName($oIE, "Text4") Local $oGetItem = _IEGetObjByName($oIE, "getitem") _IEAction($oGetItem, "click") MsgBox($MB_SYSTEMMODAL, "Form Element Value", _IEFormElementGetValue($oGetItem)) Func _ActiveXRun() $retWin = WinGetHandle("[Class:Button]","") $winTitle = "[HANDLE:" & $retWin &"]" $ctrlHandle = ControlGetHandle($winTitle,"", "[CLASS:Button; INSTANCE:2]") $ctrlTitle = "HANDLE:" & $ctrlHandle &"]" WinWaitActive($ctrlTitle,"[CLASS:Button; INSTANCE:2]",10) $k = ControlGetPos($winTitle, "","[CLASS:Button; INSTANCE:2]") $x = $k[0] $y = $k[1] WinActivate ($winTitle,"An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?") ControlFocus($winTitle,"An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?","[CLASS:Button; INSTANCE:2]") ControlClick($winTitle, "","[CLASS:Button; INSTANCE:2]","primary",1,$x,$y) ControlSend($winTitle, "", "[CLASS:Button; INSTANCE:2]", "{ENTER}", 0) EndFunc Here is the console output.
      >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.1.au3" /UserParams +>12:44:11 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v. Keyboard:00000409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\april\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\april\AppData\Local\AutoIt v3\SciTE >Running AU3Check ( from:C:\Program Files (x86)\AutoIt3 input:C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.1.au3 +>12:44:11 AU3Check ended.rc:0 >Running:(\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.1.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop "C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.1.au3" (31) : ==> Subscript used on non-accessible variable.: $x = $k[0] $x = $k^ ERROR ->12:44:24 AutoIt3.exe ended.rc:1 +>12:44:24 AutoIt3Wrapper Finished. >Exit code: 1 Time: 13.76 I also tried a simpler code.
      include <IE.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> _IECreate("C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\sampleAWD10.html",0,1,0) Local $oIE = _IEAttach("", "instance", 1) _IELoadWait($oIE) $k = ControlGetPos("[CLASS:#32770]", "","[CLASS:Button; INSTANCE:2]") $x = $k[0] $y = $k[1] ControlClick("[CLASS:#32770]", "","[CLASS:Button; INSTANCE:2]","primary",1,$x,$y) Local $oLastName = _IEGetObjByName($oIE, "Text4") Local $oGetItem = _IEGetObjByName($oIE, "getitem") _IEAction($oGetItem, "click") MsgBox($MB_SYSTEMMODAL, "Form Element Value", _IEFormElementGetValue($oGetItem)) There's no error in the console output for the 2nd code I have tried.
      And here is the Window Info for the ActiveX prompt.
      >>>> Window <<<< Title: Internet Explorer Class: #32770 Position: 580, 338 Size: 376, 146 Style: 0x94C808C4 ExStyle: 0x00010101 Handle: 0x00000000001516FA >>>> Control <<<< Class: Button Instance: 2 ClassnameNN: Button2 Name: Advanced (Class): [CLASS:Button; INSTANCE:2] ID: 1 Text: &Yes Position: 184, 77 Size: 80, 22 ControlClick Coords: 37, 12 Style: 0x50010000 ExStyle: 0x00000004 Handle: 0x00000000001215DE >>>> Mouse <<<< Position: 228, 120 Cursor ID: 0 Color: 0xFFFFFF >>>> StatusBar <<<< >>>> ToolsBar <<<< >>>> Visible Text <<<< &No An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction? &Yes >>>> Hidden Text <<<<  

    • lacamel
      By lacamel
      Hi there,
      I did a short script to simulate mouse click when pixel change is detected on a small section of the screen. I recorded the screen many times to see the accuracy of the script and it seems though response time varies widely.
      Here's the script 
      $checksum = pixelchecksum (400,250, 402,252)
      While $checksum = pixelchecksum (400,250, 402,252)
      Sleep (50)
      Sleep (300)
      Mouseclick("left", 450,300, 1, 0)
      Counting from the pixel change to the mouse click, i get response times anywhere between 370ms and 550ms. I've tried running au3 and exe, changed sleep times but never gotten an accurate response time based on the script. Any ideas why?