Sign in to follow this  
Followers 0
GDB2222

How to send keystrokes to a minimised app without changing focus

8 posts in this topic

I want to continue working on whatever else I happen to be doing and occasionally send some text to another, minimised, application using autoit. Ideally, I don't want to be aware that this is happening. So far, the best I have been able to come up with is to switch focus, send the keys, then switch back to the original app. The code is as follows:

$handleAct = WinGetHandle("[ACTIVE]") ; Get handle of current application

$handleNotepad = WinGetHandle("Untitled - Notepad") ; Get handle of Notepad - which is already running

Sleep (5000) ; Continue to work on current app

WinActivate ($handleNotepad) ; activate notepad and send some text

send("text to notepad {ENTER}")

send("text2 to notepad {ENTER}")

WinActivate($handleAct) ; revert back to original app

This is very clunky. There must be a better way, no?

Share this post


Link to post
Share on other sites



Your alternative could be to use

ControlSend
.

Thanks for the VERY quick response. That is an excellent idea. Sadly, this is not a standard windows programme, and the info tool does not list any controls. Any other ideas?

BTW, can you change the rate at which key strokes are sent?

Share this post


Link to post
Share on other sites

Try using ControlSend without specifying the control parameter, use an empty string. That sometimes works.

The rate at which keys are sent can be controlled with the AutoIt options SendKeyDelay and SendKeyDownDelay. See

AutoItSetOption
.

Share this post


Link to post
Share on other sites

Try using ControlSend without specifying the control parameter, use an empty string. That sometimes works.

Thanks - that works brilliantly. Problem solved.

Share this post


Link to post
Share on other sites

Sorry, I can't see a 'mark as answered' button.

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
Sign in to follow this  
Followers 0