Forum Discussion

Josh_147's avatar
Josh_147
Contributor
4 years ago
Solved

How to get the FullName of current focus/VisibleOnScreen window?

Hi all,

 

In VBScript, we used to hard-coded the parameter like this:

Set sDlg = Sys.Process("notepad").Window("Notepad", "New Text Document.txt - Notepad", 1)

 

Instead of hard-coded it, can we get the FullName of the object (window) which is currently focus / topmost on the screen?

 

Thanks.

 

-------

Edited:

Basically I want to make this parameter as a dynamic parameter which a function will get the current focus window's FullName and pass into the script. Is there any function able to do this?

  • Hi,

     

    Something like this (untested pseudocode):

      arWindows = <process>.FindAllChildren("WndClass", "*", 1).toArray(); // top-level children
    
      var strFullName = '';
      if (arWindows.length > 0)
      {
        for (var i = 0; i < arWindows.length; i++)
          if (arWindows[i].Focused)
          {
            strFullName = arWindows[i].FullName;
            break;
          }
      }
    

     

5 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    Use Object Spy on the window - can you see FullName in there?

    • Josh_147's avatar
      Josh_147
      Contributor

      Hi Marsha_R ,

       

      Sorry that I should write the question in more details. I had updated the question.

       

      I 'm looking for how to make the parameter (FullName) as a dynamic parameter. Which means we run the script and it will get the FullName of current focused window, then pass the parameter back into the script.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    This is not possible out of the box. But you can search for all windows of the tested application up to certain depth and iterate through the obtained list and check the value of the .Focused property to determine the window that currently has input focus.

     

    • Josh_147's avatar
      Josh_147
      Contributor

      Hi AlexKaras ,

       

      Thanks for the idea, it seems like possible to work on it. Is there any example to show how can we get the FullName of the window that currently has input focus?

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        Something like this (untested pseudocode):

          arWindows = <process>.FindAllChildren("WndClass", "*", 1).toArray(); // top-level children
        
          var strFullName = '';
          if (arWindows.length > 0)
          {
            for (var i = 0; i < arWindows.length; i++)
              if (arWindows[i].Focused)
              {
                strFullName = arWindows[i].FullName;
                break;
              }
          }