Jump to content

Send Keys to Control in inactive window


Recommended Posts

Hello,

I'm a newbie with Autoit, but managed to do a simple script that works with our erp system (qad) when opened in active window.
The commands were sent using Send, MouseClick etc.

But it doesn't work on a remote machine if the rdc is closed or minimised.
I figured I need to change the commands to ControlSend, ControlClick etc.

I used the Window Info Tool to map the login screen, but it seems the control IDs keep changing in every program run and addressing using control class/ classnn and instance (as shown in info tool) does not seem to work for some reason (see console output when trying to address the control)

Opt("WinTitleMatchMode", 4) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
;start QAD
Local $autoRunQAD = Run("C:\Program Files (x86)\QAD\QAD Enterprise Applications 2011 SE\QAD.Applications.exe", "", @SW_SHOWMAXIMIZED)
Sleep(3000) ;inicializace
Local $hWnd = WinWait("[CLASS:WindowsForms10.Window.8.app.0.2004eee]", "", 1)

;attempt to address the login name and password controls using class and instance:
$hCtrl1 = ControlGetHandle($hWnd,"","[class:WindowsForms10.Window.8.app.0.2004eee;instance:8]") ;login name
ConsoleWrite("$hCtrl method 1: " & $hCtrl1 & @CRLF)
;attempt to address the login name and password controls using classnn :
$hCtrl1 = ControlGetHandle($hWnd,"","[classnn:WindowsForms10.Window.8.app.0.2004eee8]") ;login name
ConsoleWrite("$hCtrl method 2: " & $hCtrl1 & @CRLF)

$hCtrl2 = ControlGetHandle($hWnd,"","WindowsForms10.Window.8.app.0.2004eee6") ;heslo

Sleep(50)
ControlSend($hWnd, "", $hCtrl1, "konecny")

------------------------------------------------------------------

Console Output:

$hCtrl method 1: 0x00000000
$hCtrl method 2: 0x00000000

------------------------------------------------------------------

... as a result, the qad login screen gets filled using the ControlSend pointing to 0x00000000 (last line of code) and i can {tab} between the controls, but again this does not work when the window / rdc / is not active.

Perhaps somebody can point me in the right direction?

I also tried to test the login screen window for controls using the "WinListChildren" function I got from here: https://www.autoitscript.com/forum/topic/98583-list-all-child-controls-of-a-given-window/
...with this disappointing result:
 

image.png.c8170988c305e0a430f6f43d928c9cd6.png


Thank you,
Daniel Konecny

image.png

image2.png

Link to comment
Share on other sites

Update: after further tests I managed to get the handles of the controls in login window.
But neither ControlSend nor ControlSetText does change their text, they remain empty.

Sleep(3000) ;inicializace
Local $hWnd = WinWait("[CLASS:WindowsForms10.Window.8.app.0.2004eee]", "", 1)

$hCtrl1 = ControlGetHandle("[CLASS:WindowsForms10.Window.8.app.0.2004eee]","","[ClassNN:WindowsForms10.Window.8.app.0.2004eee8]") ;login name
$hCtrl2 = ControlGetHandle("[CLASS:WindowsForms10.Window.8.app.0.2004eee]","","[ClassNN:WindowsForms10.Window.8.app.0.2004eee6]") ;password
ConsoleWrite("$hWnd: " & $hWnd & @CRLF)
ConsoleWrite("$hCtrl1 method 1: " & $hCtrl1 & @CRLF)
ConsoleWrite("$hCtrl2 method 1: " & $hCtrl2 & @CRLF)

Sleep(50)
ControlSend($hWnd, "", $hCtrl1, "test")
Sleep(50)
ControlSetText($hWnd, "", $hCtrl1, "test")
Sleep(50)
ControlSend($hWnd, "", $hCtrl2, "test")
Sleep(50)
ControlSetText($hWnd, "", $hCtrl2, "test")
Sleep(50)

Console output:
$hWnd: 0x002B097C
$hCtrl1 method 1: 0x00290AA2
$hCtrl2 method 1: 0x00280B98

(I also tried another instance nr.'s in the ClassNN: .... eee, all available (1-10) just in case but none of them works in changing any text in the logon screen)

Link to comment
Share on other sites

Thank you for your reply.
At first not, because since they change with every start of the app, I thought they are unsuitable for identification of the control.
Your reply made me re-think this and using the "GetAllWindowsControls" form this forum I gathered the control ID's from a static (already opened) instance of the program.
And yes, addressing the controls by their ID's does make the ControlClick, ControlSend and ControlSetText do stuff (I need to inspect this in detail as it seems that some of the controls /password/ are loaded after others /username/ are filled).

So I guess the way to go for me is to find a way to obtain the ID's of the respective controls at runtime, after the window in instantialized and after other controls are operated by the script.
Is there some simplier way to achieve it than to emulate the "GetAllWindowsControls" ?


 

Link to comment
Share on other sites

It turned out that the odd behaviour si caused by an improper identification of the window handle in the first place.
The title containing eastern european characters is probably the cause.
I opened another thread related to it:

 

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