Page 1 of 1

Controlsend in HiddenWindows

Posted: 22 Oct 2019, 18:12
by c7aesa7r

Code: Select all

DetectHiddenWindows, On

IniRead, Mensagem, C:\alarms\scripts\settings\mensagem.ini, mensagem, nome
IniRead, Nome, C:\alarms\scripts\settings\mensagem.ini, mensagem, mensagem
IniRead, Cliente, C:\alarms\scripts\settings\mensagem.ini, cliente, numero


SetKeyDelay, 0
ControlSend, , {F11}{F11}{F11}{F11}%Mensagem%{NUMPADMULT}%Nome%, ahk_exe %Cliente%.exe
Sleep, 120
ControlSend, ,{ENTER}, ahk_exe %Cliente%.exe
My script works correctly in minimized windows, now trying make the script work with hidden windows, but when i add DetectHiddenWindows, On, the script stop working in all type of windows (minimized/hidden), what im doing wrong?

Re: Controlsend in HiddenWindows

Posted: 22 Oct 2019, 18:19
by Hellbent
Could be related to this.
https://www.autohotkey.com/docs/commands/DetectHiddenWindows.htm wrote:
Turning on DetectHiddenWindows can make scripting harder in some cases since some hidden system windows might accidentally match the title or text of another window you're trying to work with. So most scripts should leave this setting turned off. However, turning it on may be useful if you wish to work with hidden windows directly without first using WinShow to unhide them.
Looks like this might be a workaround.
Turning on DetectHiddenWindows is not necessary when accessing a control or child window via the ahk_id method or as the last-found-window. It is also not necessary when accessing GUI windows via Gui +LastFound.

Re: Controlsend in HiddenWindows

Posted: 22 Oct 2019, 18:53
by c7aesa7r

Code: Select all

IniRead, Mensagem, C:\pokexgames_alarms\scripts\settings\mensagem.ini, mensagem, nome
IniRead, Nome, C:\alarms\scripts\settings\mensagem.ini, mensagem, mensagem
IniRead, Cliente, C:\alarms\scripts\settings\mensagem.ini, cliente, numero


ControlHwnd := 0x407B2
SetKeyDelay, 0
ControlSend, , {F11}{F11}{F11}{F11}%Mensagem%{NUMPADMULT}%Nome%, ahk_id %ControlHwnd%
Sleep, 120
ControlSend, ,{ENTER}, ahk_id %ControlHwnd%
Ive tried using ahk_id but only work with minimized window, when it goes hidden script dont work

Re: Controlsend in HiddenWindows

Posted: 22 Oct 2019, 19:08
by Hellbent
I've never tried using controlsend before, but I do know that ControlClick can behave differently from app to app. On some it works flawlessly, others it won't work if the winodw is active, others it won't work if the app isn't hidden, others it doesn't care where I tell it to click it just clicks where my cursor is, and so on. That might not be the case with ControlSend, but who knows.

Other than posting what the doc said could cause what you described I can't offer any insight. It's just not something I've had to deal with.

Anyway, I wish you luck.

Re: Controlsend in HiddenWindows

Posted: 22 Oct 2019, 20:25
by Xtra
Assigning a variable like this ControlHwnd := 0x407B2 will not work you need to retrieve the hwnd every time the script it run.

For controls:

Code: Select all

;~ ControlGet, OutputVar, Hwnd [,, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]
ControlGet, myHwnd, Hwnd, myControl, myWinTitle
For windows:

Code: Select all

;~ WinGet, OutputVar [, SubCommand, WinTitle, WinText, ExcludeTitle, ExcludeText]
WinGet, myHwnd, ID, myWinTitle

Re: Controlsend in HiddenWindows

Posted: 22 Oct 2019, 20:28
by gregster
Note:
I posted this originally in a duplicate of this topic without noticing Hellbent's already existing answers about ahk_ids - so this might not help much further.
Anyway, I moved this post, so that the duplicate topic could be removed:


One ControlSend command only sends its keys once, to the first matching window it finds. Hidden windows might add new matching windows to the mix that before wouldn't be found:
https://www.autohotkey.com/docs/commands/DetectHiddenWindows.htm#Remarks wrote:Turning on DetectHiddenWindows can make scripting harder in some cases since some hidden system windows might accidentally match the title or text of another window you're trying to work with. So most scripts should leave this setting turned off.
https://www.autohotkey.com/docs/misc/WinTitle.htm#Matching wrote:If multiple windows match the WinTitle and any other criteria, the topmost matching window is used. If the active window matches the criteria, it usually takes precedence since it is usually above all other windows.
There might be other hidden (or still visible) windows/processes with the same ahk_exe property that your script sends to - this property is not necessarily unique to a single window. WinGet, , List ((or a look into the task manager) might help to clear this up.

Btw, how do you know that your keys don't get send ? Do you hide/unhide these windows yourself ?

Perhaps save their unique ahk_ids immediately before hiding these windows, so that you can use these IDs in ControlSend's wintitle parameter afterwards, instead of ahk_exe. That should take care of the ambiguity...