StMaSi Posted August 2 Share Posted August 2 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 More sharing options...
bogQ Posted August 2 Share Posted August 2 (edited) 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 August 2 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) 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 More sharing options...
Nine Posted August 2 Share Posted August 2 (edited) 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 August 2 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
StMaSi Posted August 2 Author Share Posted August 2 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 More sharing options...
Nine Posted August 2 Share Posted August 2 (edited) 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 August 2 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
StMaSi Posted August 2 Author Share Posted August 2 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 More sharing options...
StMaSi Posted August 2 Author Share Posted August 2 Update. I used "{SPACE}" since there wasn't a shortcut present, but still only works if that Timeout Warning window is top most. Link to comment Share on other sites More sharing options...
Nine Posted August 2 Share Posted August 2 Can you kill that window instead of clicking it ? Would make it easier IMO. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
StMaSi Posted August 2 Author Share Posted August 2 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 More sharing options...
Solution Nine Posted August 2 Solution Share Posted August 2 (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 August 2 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
StMaSi Posted August 6 Author Share Posted August 6 Working on testing... Link to comment Share on other sites More sharing options...
StMaSi Posted August 26 Author Share Posted August 26 Thanx, Nine! Your code helped with the solution. After removing the secondary "" (text in window) in the functions, it is working. While 1 WinWait("Timeout Warning") WinActivate("Timeout Warning") Sleep(500) ControlClick("Timeout Warning", "", "[NAME:m_btnStayLoggedIn]") WEnd Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now