Jump to content
Gar

How do I 'Send' keys to an inactive window without gaining focus?

Recommended Posts

Gar

I searched through pretty much every related post on this forum. Alot of the posts link to inexplicably advanced techniques I don't understand. I would really appreciate some help with this specific problem. I have medium autoit code understanding, so if you simply link me to some gigantic post with pages and pages of undocumented code, I won't be able to understand it.

I need to Send the f key to an inactive window and have it remain inactive while doing so. There are no useable controls. Does anyone know how to do this? And, if so, can you walk me through how I would send the f key to an inactive window, if the answer turns out to involve PostMessage, dlls, and such? I don't really understand their use. Thanks!

Edited by Gar

Share this post


Link to post
Share on other sites
sdrawkcab

I'm having the same problem!

I've found lots of references to _SendMessage but I am unsure of the syntax to use. For example, how do I get it to send an ARROW UP keystroke directly to a window process?

The window I am trying to control does not have any ControlIDs which are usable for my purpose.

I've found AutoIt to be very useful and I'm surprised to be stumped by what must be a fairly common problem.

Share this post


Link to post
Share on other sites
enaiman

Earlier versions of AutoIt were able to do it - if you want to use one of them I would suggest 3.2.1.0

That version allowed ControlSend to an empty control no matter if the window was active or not.

After 3.2.1.0 however the ControlSend changed so it no longer works for empty controls when the window is inactive. Send also can't be used because it sends to active window.

You can download that version, write the script, compile it and it will work.

Good luck,


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
Gar

Thanks. I downloaded 3.2.0.1 because there was no 3.2.1.0 in the archive. I will let others know how it goes.

Edited by Gar

Share this post


Link to post
Share on other sites
enaiman

It was a long discussion about this and I asked myself if this ControlSend can be made like it was ... well, the conclusion was ... NO :)

About 3.2.0.1 - that's the version (sorry for confusion).


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
Gar

Unfortunately, 3.2.0.1 did not work. The window still needed focus. It seemed that ControlSend with no control id just functioned as Send.

Share this post


Link to post
Share on other sites
enaiman

Nope - and here is a small script allowing you to see that it works on inactive window:

Run("notepad.exe")

WinWait("Untitled")

WinSetState("Untitled", "", @SW_MINIMIZE)

ControlSend("Untitled", "", "", "This is a test")

WinSetState("Untitled", "", @SW_RESTORE)

Please note the ControlId is empty. If it works (I am sure it will) you will see "This is a test" written in Notepad.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
faldo

I just downloaded 3.2.0.1 (i have the same problem as Gar) and the snippet in the above post didn't write anything in notepad.

I'm sure this worked a while back with an older version but since i never dreamt of that ControlSend would go back to needing a controlID i lost track of what version it was.

Would be great if someone else posted a working method.

Share this post


Link to post
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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.