Jump to content

How to prevent AutoIT script from opening source folder and stealing focus


Go to solution Solved by Nine,

Recommended Posts

Have script that watches for specific window to be presented, then clicks a specific button on said window to close it out.

Script works without issue, but when it triggers, it opens it's own source folder and steals focus from whatever I'm currently working on.

While 1
    WinWait("Timeout Warning", "")
    If WinExists("Timeout Warning", "") Then
        WinActivate("Timeout Warning", "")
        ControlClick("Timeout Warning", "", "[NAME:m_buttonStillWorking]")
    EndIf
    Sleep(25000)
WEnd

How do I prevent the script from opening it's own source folder and stealing focus from whatever I'm currently working on?

Thanks in advance.

Link to comment
Share on other sites

You do call WinActivate... and that function do make focus on window

Does ControlClick works on that window only if you have focus?

So question is will something like this work in your case with no WinActivate ?

 

While 1
    $hwnd = WinWait("Timeout Warning")
    If $hwnd Then
        ControlClick($hwnd , "", "[NAME:m_buttonStillWorking]")
    EndIf
    Sleep(25000)
WEnd

 

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

If the button has a shortcut, you may wanna try to ControlSend it instead of clicking it.  FYI, you may not need to specify the control, just use :

ControlSend($hWnd, "", "", <shortcut here>)

ps. as @bogQ said do not WinActivate the window

Edited by Nine
Link to comment
Share on other sites

1 hour ago, bogQ said:

You do call WinActivate... and that function do make focus on window

Does ControlClick works on that window only if you have focus?

So question is will something like this work in your case with no WinActivate ?

 

While 1
    $hwnd = WinWait("Timeout Warning")
    If $hwnd Then
        ControlClick($hwnd , "", "[NAME:m_buttonStillWorking]")
    EndIf
    Sleep(25000)
WEnd

 

bogQ, this only works when the window is topmost. Most of the time it is hidden behind other windows and then it is ignored.

1 hour ago, Nine said:

If the button has a shortcut, you may wanna try to ControlSend it instead of clicking it.  FYI, you may not need to specify the control, just use :

ControlSend($hWnd, "", "", <shortcut here>)

ps. as @bogQ said do not WinActivate the window

Nine, when using au3Info, I do not see anything identifying a shortcut.

Link to comment
Share on other sites

It has nothing to do with au3info.  When the window appears, press Alt to see if there is an underlined character in the button you want to click on.  That will be the shortcut you will want to use.

Edited by Nine
Link to comment
Share on other sites

46 minutes ago, Nine said:

It has nothing to do with au3info.  When the window appears, press Alt to see if there is an underlined character in the button you want to click on.  That will be the shortcut you will want to use.

Sadly, no underlined characters on the buttons when pressing the ALT key. However, it appears as though the "Still Working" button is highlighted by default. Is there an easy way to target that default button?

Link to comment
Share on other sites

20 minutes ago, Nine said:

Can you kill that window instead of clicking it ?  Would make it easier IMO.

Yes, the window can be killed, but that would defeat the purpose. It is a inactivity timeout window for an app. If I kill the window, the app will terminate. The goal is to click the window in order to extend the timeout.

Link to comment
Share on other sites

  • Solution
Posted (edited)

Well in that case there is not much you can do.  But you could reduce the impact of the focus lost this way :

#include "..\BlockInput\BlockInputUDF.au3"

HotKeySet("{F1}", Terminate)

Local $hWnd, $hCurr
While True
  $hWnd = WinWait("Enregistrer sous") ; Timeout Warning
  $hCurr = WinGetHandle("[ACTIVE]")
  ConsoleWrite(WinGetTitle($hCurr) & @CRLF)
  _BlockInput($BI_DISABLE)
  WinActivate($hWnd)
  ControlClick($hWnd, "", "Button3") ; [NAME:m_buttonStillWorking] or use ControlSend (see which is faster)
  WinSetOnTop($hCurr, "", $WINDOWS_ONTOP)
  WinActivate($hCurr)
  _BlockInput($BI_ENABLE)
  WinSetOnTop($hCurr, "", $WINDOWS_NOONTOP)
  WinActivate($hCurr)
WEnd

Func Terminate()
  Exit
EndFunc

There is no need to test the existence of the window as WinWait will wait forever for that window to appear.  Also there is no need to add Sleep in the loop for the exact same reason.  I needed to have 2 WinActivate because with Notepad it was not enough to gain full focus.  Probably a question of timing but I didn't want to add any sleep there.

I tested it with Notepad and it is working correctly.  See my signature for the UDF.

Edit :  After testing some more with Notepad, I can confirm that it was a timing issue.  You may be able to remove WinSetOnTop statements, and only use one WinActivate.  Just play with it, see what is working or not with your application.

Edited by Nine
Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...