Jump to content

Script that changes focus back to main GUI stops working after modal popup is detected


Yodavish
 Share

Recommended Posts

I have 2 questions both are related in the same area of my script.

First, the script will check for a specific Internet Explorer title is active if so, it forces the focus back to GUI window input box. The one time it doesn't is when it detects an elemental name within a modal popup. When this does happen, it will go to an event handler to wait for a button to be clicked and then shift focus back to the GUI window input box. This works fine when the AutoIt script is first launched with a refreshed browser since the "_IEGetObjByName" is unable to find the element name in the modal pop up, the @error occurs.  However, once the modal pop up does occur, AutoIt will no longer send the focus back to the main GUI when the specific browser is active.  I'm sure there is a better way than to detect for the specific element name within the modal? But I'm not sure. Here is the core AutoIt script that I'm speaking of:

While 1
   If WinActive($proTrackerWindowTitle) Then
      ConsoleWrite('+ While loop ProTracker active detected! ' & @MSEC & @CRLF)
      $ie = _IEAttach("ProTracker")
      ConsoleWrite('+ While loop ProTracker _IEAttach! ' & @MSEC & @CRLF)
      $mismatchButton = _IEGetObjByName($ie, $proTrackerMisMatchButtonId)
      ConsoleWrite('+ While loop ProTracker _IEGetObjByName ' & @MSEC & @CRLF)
      $oEvent = ObjEvent($mismatchButton, "mismatchButton_")
      If @error Then setMainWindow()
   EndIf
   Sleep(100) ; Sleep to reduce CPU usage
WEnd

Func mismatchButton_onclick($oEvtObj)
   ConsoleWrite('_MY_EVENT_HANDLER_onclick: ' & $oEvtObj & @CRLF)
   setMainWindow()
EndFunc

Func setMainWindow()
    consoleWrite("setMainWindow initiated: " & @CRLF)
    ; resets focus back to main GUI window
    WinActivate($mainWindow)
    consoleWrite("setMainWindow WinActivate: " & @MSEC & @CRLF)
    $hWnd = WinWait($mainWindow)
    consoleWrite("setMainWindow WinWait: " & @MSEC & @CRLF)
    WinSetOnTop($hWnd, "", $WINDOWS_ONTOP)
    consoleWrite("setMainWindow WinSetOnTop: " & @MSEC & @CRLF)
    ControlFocus($hWnd, "", $inputScan)
    consoleWrite("setMainWindow complete: " & @MSEC & @CRLF)
 EndFunc

Second, when the modal does pop up and I click the mismatched button, the Autoit event handler sends it 3-4 times. Is this correct? How can I reduce it to only when it clicks once? Here are the SciLite Logs of the event handler:

_MY_EVENT_HANDLER_onclick: 0
setMainWindow initiated: 
setMainWindow WinActivate: 042
setMainWindow WinWait: 053
setMainWindow WinSetOnTop: 053
setMainWindow complete: 053
_MY_EVENT_HANDLER_onclick: 0
setMainWindow initiated: 
setMainWindow WinActivate: 053
setMainWindow WinWait: 063
setMainWindow WinSetOnTop: 063
setMainWindow complete: 063
_MY_EVENT_HANDLER_onclick: 0
setMainWindow initiated: 
setMainWindow WinActivate: 064
setMainWindow WinWait: 075
setMainWindow WinSetOnTop: 075
setMainWindow complete: 075

 

Edited by Yodavish
logs are way to long. Updated to make it easier to read.
Link to comment
Share on other sites

my guess would be that you never disable the window from being set to on top. so its never going to be able to focus on the gui again bc the internet explorer window will always be on top.  it may actually focus on the gui window but it will never override the winsetontop setting unless you disable it or enable some kinda priority if thats even possible.

Link to comment
Share on other sites

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...