ControlSetText not able to set value of control if window not active

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

ControlSetText not able to set value of control if window not active

13 Nov 2015, 08:57

I am re-writing some code, and I have run into an issue that I just can't understand.

Here is the code I am using (For automating the Login window of the RDP client):

Code: Select all

	Login(username, password){
		;WinActivate, % "ahk_id " this.hwnd
		ControlSend, , {down}, % "ahk_id " this.hwnd
		Sleep % this.DefaultSleep
		ControlSetText, Edit2, % username, % "ahk_id " this.hwnd
		Sleep % this.DefaultSleep
		ControlSetText, Edit3, % password, % "ahk_id " this.hwnd
		Sleep % this.DefaultSleep
		while (WinExist("ahk_id " this.hwnd)){
			ControlClick, Button2, % "ahk_id " this.hwnd
			Sleep % this.DefaultSleep
		}
	}
This code only works if the login window is active, yet I am specifying the HWND of the window in the WinTitle param.
If I uncomment the WinActivate statement, it works (as long as you do not click anywhere else while it is running)
Any ideas on what is wrong? It should be able to function without the Login window having focus surely?
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: ControlSetText not able to set value of control if window not active

13 Nov 2015, 09:06

in theory yes.
but it might be something specific to the application.
for example if I use a GUI and take over the an EDIT CONTROL's procedure or the window, when it receives the WM_SETTEXT, it test if the edit control has focus or not or the window is active or not and proceed appropriately (don't do anything in this case). just an idea

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Hugh Jars, Mateusz53, MrDoge, peter_ahk and 379 guests