Python Send Keystrokes to Non-Active Application

10,541

Solution 1

pywinauto is another MS-only GUI automation tool, this one written in Python.

Solution 2

SendKeys is a Python module for Windows that can send one or more keystrokes or keystroke combinations to the active window.

If you need to do some automated work in the background, make another user/session and do it in that.

However if you must do something of this like on windows, I always reach for autoit.

It's M$ only and perfectly suited to automating tasks on that OS.

Solution 3

This is a frequent question in the autohotkey.com forums. Search under "sending commands to controls". Basically, if you have the control ID, then it doesn't need to be visible in order to operate on it. There're more details on the forums.

good luck!

Share:
10,541
exupero
Author by

exupero

Updated on June 13, 2022

Comments

  • exupero
    exupero almost 2 years

    I'm automating some common GUI tasks I have to do in an application, and I'm using a Python program and SendKeys to do it. So far I've had to activate the application I'm sending keys to (since SendKeys just sends the keystrokes to the active window), but I'd like to be able to send keystrokes to an application in the background. Is there a way to do that, or am I dreaming an impossible dream?

    Thanks for your help.

  • Alex Osheter
    Alex Osheter about 6 years
    Heads up, this URL is dead now. Try this instead.