Search code examples
loopsclickwindowfocusautoit

Focus window in background in AutoIt (MouseClick)


I'd like to download GTA V for PC. The download is extremely slow (40kb/s), but when you click pause and then start it again downloads with 5,5mb/s for 1 minute.

I want to write a script for it in AutoIt.

But how i can focus the window AND work on in the foreground.

The window info of the download manager (mouse pointed at the button) https://i.sstatic.net/ry5dq.png

My script looks like this at the moment:

While 1

; Here, the focus has to go, right?

MouseClick ( "primary" [, 637, 460 [, clicks = 1 [, speed = 0]]] )
Sleep(1000)
MouseClick ( "primary" [, 637, 460 [, clicks = 1 [, speed = 0]]] )

Sleep(60000)
WEnd

Solution

  • Ensure that you got right coords from Autoit Window Info screenshot

    Try to use WinActivate() and ControlClick() (in that choice the mouse is not used) :

      Opt("MouseCoordMode",2)     
      While 1
       $hwnd = WinActivate('Launcher')
       MouseClick ( "primary",637 ,460) ; with mouse coords
       Sleep(1000)
       ControlClick ( $hwnd, "", "[CLASS:AfxWnd110su; INSTANCE:2]") ;... and without mouse
       Sleep(60000)
       WinSetState ( $hwnd, "", @SW_MINIMIZE ); Minimaze the Launcher
      WEnd