SetFocus to a hidden window without revealing the window

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
deMute
Newbie
Posts: 4
Joined: Thu Mar 05, 2009 4:59 am

SetFocus to a hidden window without revealing the window

Post by deMute » Thu Mar 05, 2009 12:50 pm

Hi,

How do I focus on a hidden window without that window becoming visible? I've read th post here which almost does what I'm looking for:
http://www.mjtnet.com/forum/viewtopic.p ... hidewindow
but this method for hiding the winodw takes long enough that it is noticable to the user.

Any help would be greatly appreciated.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Mar 05, 2009 1:10 pm

That's not possible. Focus means making the window able to accept keyboard input. Therefore a focused window must be visible.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Mar 05, 2009 1:24 pm

Technically Marcus is correct but as a practical matter if the windows transparency is set to "1", the window is technically visible but still does not show up on the screen.

HERE is a sample of doing exactly that. Setting the window's transparency/opacity to one then setting focus to the window.

deMute
Newbie
Posts: 4
Joined: Thu Mar 05, 2009 4:59 am

Post by deMute » Thu Mar 05, 2009 1:38 pm

Thanks for your response but I already have code which makes the window hidden and allows me to send input to it (based on the post I mentioned):

Code: Select all

Let>HWND_TOPMOST=-1
Let>HWND_NOTOPMOST=-2
Let>HWND_BOTTOM=1
Let>SWP_NOSIZE=1
Let>SWP_NOMOVE=2
Let>SWP_NOACTIVATE=16
Let>SWP_SHOWWINDOW=64
Let>SWP_HIDEWINDOW=128
Let>Flags={%SWP_HIDEWINDOW% Or %SWP_NOACTIVATE% Or %SWP_NOSIZE% Or %SWP_NOMOVE%}

GetWindowHandle>Settings*,winhandle
LibFunc>User32,SetWindowPos,swpr,winhandle,HWND_BOTTOM,0,0,0,0,Flags

wait>1

Press ALT
	  Send Character/Text>f
Release ALT
My problem is not that I can't make a hidden window accept input. My problem is that I can't make the window hidden fast enough.

deMute
Newbie
Posts: 4
Joined: Thu Mar 05, 2009 4:59 am

Post by deMute » Thu Mar 05, 2009 1:40 pm

Thanks a lot JRL. This sounds like exactly what I need }:o) I'll give it a try.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Mar 05, 2009 1:42 pm

but this method for hiding the winodw takes long enough that it is noticable to the user.
The method I mentioned HERE will not be noticeable to the user.

deMute
Newbie
Posts: 4
Joined: Thu Mar 05, 2009 4:59 am

Post by deMute » Thu Mar 05, 2009 2:11 pm

Wow, thanks again JRL! That works even better than I imagined possible. That's a very very nice trick indeed :)

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts