Jump to content

Scripting keyboard input to a non-active window.


Recommended Posts

Right now I am using the excellent Auto-It v3 to script some commands to send to a specific window. However, the window must be active to receive the command. How would I use Auto-It (or if that is not possible, some other scripting solution) to send keyboard input to the window while it is inactive and perhaps even minimized? Also, can it be completely separate from user keyboard input so if I am typing while the script is sending, it won't get confused?

Link to comment
Share on other sites

I have used the following code to send some text to EditPad lite whisl minimized. There are limitation on what can be sent using "ControlSend"

ControlSend("EditPad Lite","","TEditPadEditor1", "Text sent to a minimized window")

Search the helpfile for ControlSend, also use AutoIt Window Spy (included with Autoit) for calssnames, windows title etc.

Hope it helps

CheersNobby

Link to comment
Share on other sites

Guest BL@(K-R34P3R

No there is a better way. Do this:

Run("programblahblahblah")

WinWaitActive("Blah")

;Here is what you want...

WinSetState ( "title", "text", flag @SW_MINIMIZE)

;Then run the Send() command or whatever, this will not work with mouse clicks or anything using mouse movement, only stuff like send commands etc...

Link to comment
Share on other sites

Not a better way because as soon as another window gets the focus, the send is passed on to that window, not the minimized one.

So if you want to browse the net or type a document whilst autoit is happily passing keystrokes to notepad in the background, you have to look at ControlSend

CheersNobby

Link to comment
Share on other sites

Guest BL@(K-R34P3R

Yes, I thought I said that above, guess not. But yes, you can't do anything else while its running. But hopefully... you won't be sending too mcuh, like a 13 character string aka 13 9's =). I've got 3 computers running it right now.

Link to comment
Share on other sites

Yes, I thought I said that above, guess not. But yes, you can't do anything else while its running. But hopefully... you won't be sending too mcuh, like a 13 character string aka 13 9's =). I've got 3 computers running it right now.

<{POST_SNAPBACK}>

controlsend would let you do it at the same time as doing other things.

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

I implemented the ControlSend solution but I have found that the program *needs* focus to go from one stage to another so complete background operation appears impossible at this point. However, ControlSend itself did do what I needed it to do!

Thank you nobby, BL@(K-R34P3R, and emmanuel for all of your help!

If you wish to delve further into the focus problem, then the program I am trying to automate is Warcraft 3: The Frozen Throne. When one goes from one stage to another (say by hitting alt-g to play a custom game) Warcraft 3 will not fully arrive at the next stage (the custom game list in this case) until it has been given focus. Therefore any other keystrokes sent to Warcraft 3 are thrown away until it is given focus so that it may complete the stage-transition.

Or at least that is my theory. :">

How would I circumvent or solve the focus-problem?

Link to comment
Share on other sites

I implemented the ControlSend solution but I have found that the program *needs* focus to go from one stage to another so complete background operation appears impossible at this point.  However, ControlSend itself did do what I needed it to do!

Thank you nobby, BL@(K-R34P3R, and emmanuel for all of your help!

If you wish to delve further into the focus problem, then the program I am trying to automate is Warcraft 3: The Frozen Throne.  When one goes from one stage to another (say by hitting alt-g to play a custom game) Warcraft 3 will not fully arrive at the next stage (the custom game list in this case) until it has been given focus.  Therefore any other keystrokes sent to Warcraft 3 are thrown away until it is given focus so that it may complete the stage-transition.

Or at least that is my theory.  :">

How would I circumvent or solve the focus-problem?

<{POST_SNAPBACK}>

does controlfocus not work?

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

Have you thought about giving it a quick focus then minimizing and going on with the code?

You can do that with the script I am sure.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

I am really sorry guys: I screwed up.

Here is what I was trying to do:

Send alt-g to window "Warcraft III". (To enter the custom game list screen)

Send alt-c to window "Warcraft III". (To enter create custom game screen)

Now I had read in the help documentation that ControlSend doesn't support ALT however I had thought that maybe the newest version did whenever it appeared that the alt-g command went through (my script would successfully tell the game to go to the custom game list). However what was really happening is that Warcraft III accepts both alt-g and (plain old) 'g' to go to the custom game list. So really it was taking in 'g' not alt-g. That is why alt-c failed: Warcraft III is not forgiving enough to take (plain old) 'c', only alt-c.

I think I can get around the lack of the alt key by sending a few tabs and then the enter key (to focus on a button and push it).

Sorry for the mix up!

BTW, will ControlSend support the alt key in a later version of AutoIt?

Edited by Christopher Blue
Link to comment
Share on other sites

Thank you all for the help so far, but now I am running into another problem:

I am using this command to send text to a text box in Warcraft III:

ControlSend("Warcraft III", "", "", "LOTR: The Ring Wars! DL ONLY", 1)

Sometimes it shows up correctly, but more often it shows up something like this:

LOTR: The ring wars1 dl oNly

It is like the shift key has been pressed and depressed almost randomly throughout the text.

I have used AutoItSetOption("SendKeyDelay", #) to slow down the the key input speed but the script will still output incorrectly most of the time. How must I go about fixing this problem?

Edited by Christopher Blue
Link to comment
Share on other sites

Thank you for the tip Larry! However I am still having trouble. Here is my new test code:

#include <ControlSendPlus.au3>

AutoItSetOption("SendKeyDelay", 5)
ControlSendPlus("Warcraft III", "", "", "LOTR: The Ring Wars! DL ONLY", 1)

However, I am still getting output like this:

LOTR; the riNG WARS! dl ONLY

and this:

LOTR: THe ring wars! DL ONLY

What am I doing wrong?
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...