Jump to content
Sign in to follow this  

Detect Resolution and change coordinates using elseif statements

Recommended Posts


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  

  • Similar Content

    • XaelloNegative
      By XaelloNegative
      Hi team,
      I have a "well-built" autoIt exe app. Its running smooth until I open another application that when I run through the window info tool, returns as "SunAwtFrame". After running said application, my "well-built" autoIt exe app ceases to run.
      What seems to be the problem here and is there a possible turn around for it? Any suggestion or recommendation will be greatly appreciated. Thanks in advance.
    • dadalt
      By dadalt
      I have a button where I need to close it!
      I was doing through  clicking same position in screen but there are some id's that have different sizes.
      What are the possible ways to click this closable button?
      Is there a way to close it through id? Is there a way to get it's position through it's ID?  
      Thanks in advance!

    • Miliardsto
      By Miliardsto
      Hello I got this script works below and I want to do not move cursor on screen when action is performed.
      Opt("MouseCoordMode", 1) ; cause it gets whole screen coords Local $x, $y Local $search = _ImageSearch('item.bmp', 0, $x, $y, 0) If $search = 1 Then MouseMove($x, $y,0) MouseClick("right", $x, $y)) MouseMove($xMiddle, $yMiddle,0) MouseClick("left", $xMiddle, $yMiddle) EndIf I changed this above to this below and what happen is. It clicks right button and then left button but not move mouse to $x $y and then to $xMiddle $yMiddle.
      Opt("MouseCoordMode", 1) ; cause it gets whole screen coords Local $x, $y Local $search = _ImageSearch('item.bmp', 0, $x, $y, 0) If $search = 1 Then ControlClick("","",0,"secondary",1,$x,$y) ControlClick("","",0,"primary",1,$xMiddle,$yMiddle) EndIf If needed I got handle in var $hwnd
      Please tell me how parameters in ControlClick would like be
    • Fuzy
      By Fuzy
      #include <AutoItConstants.au3>
      Func Skype()
      $coords = imageSearch(0,0,-1,-1,"Skype.PNG")
      [when it find the skype icon i want it to move from these coordinates, but of insted of moving to an expecific coordinate i want it to move down from these coordinates, (there is multiple images so i cant move to an specific image)] -- Kinda having trouble telling what i want cuz english isnt my first language, sorry about that. ;X
    • kcvinu
      By kcvinu
      Hi all,
      How can i get notified when user clicks on a combo box's edit area ? This is my code so far. 
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <ComboConstants.au3> #include <ListBoxConstants.au3> Global $btn ; creates a window Global $Window_0 = GUICreate("My Window", 800, 500, -1, -1, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX)) $btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50) Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50) GUICtrlSetFont(-1,12,400) Global $lstbx = GUICtrlCreateList("FirstItem", 400,50, 200, 300) GUICtrlSetFont(-1,12,400) GUIRegisterMsg($WM_COMMAND, "MyEventCallback") GUIRegisterMsg($WM_SIZE, "MyEventCallback") GUIRegisterMsg($WM_NOTIFY, "NotifyManager") GUISetState(@SW_SHOW) GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2") GUICtrlSetData($lstbx, "Apple|Orange|Pineapple|Grape|Lemon") Do $Event = GUIGetMsg( ) Until $Event = $GUI_EVENT_CLOSE Func MyEventCallback($hwnd, $message, $wParam, $lParam) Select Case $message = $WM_COMMAND ;---------------------------------------------------------------- If LoWord($wParam) = $cmb Then ; if control id is combox's Then Local $Notification = HiWord($wParam) Select Case $Notification = $CBN_DROPDOWN ; here we check the notification code. ConsoleWrite("$CBN_DROPDOWN Worked " & @MIN & ":" & @SEC & @CRLF) Case $Notification = $CBN_EDITCHANGE ; here we check the notification code. ConsoleWrite("$CBN_EDITCHANGE Worked " & @MIN & ":" & @SEC & @CRLF) ; **** Here i want add the code for combo box clicking. EndSelect ;--------------------------------------------------------------------- ElseIf LoWord($wParam) = $lstbx Then Local $Notification = HiWord($wParam) Select Case $Notification = $LBN_SELCHANGE ConsoleWrite("$LBN_SELCHANGE" & @CRLF) EndSelect EndIf ;------------------------------------------------------------------ Case $message = $WM_SIZE EndSelect Return $GUI_RUNDEFMSG EndFunc ;==>ProGUI_EventCallback Func NotifyManager($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ;Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) If DllStructGetData($tagNMHDR, 3) = $NM_LDOWN Then ConsoleWrite("Notify Worked" & @CRLF) EndIf Return $GUI_RUNDEFMSG EndFunc Func LoWord($Variable) Return BitAND($Variable, 0xFFFF) EndFunc Func HiWord($Variable) Return BitShift($Variable, 16) EndFunc  

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.