How can I send Key-Stroke, such as <Alt-F> to active application in python?

How can I send Key-Stroke, such as <Alt-F> to active application in python?

I want to send Key stroke such as <Alt-f> to the active application(ex. Acrobat) which has focus.
myang999Asked:
Who is Participating?
 
jdpipeConnect With a Mentor Commented:
I think that you might be able to do this using win32ui (on Windows, anyway). Try looking here:

http://docs.activestate.com/activepython/2.4/pywin32/win32ui.html

Cheers
JP
0
 
_jMerliN_Commented:
http://www.rutherfurd.net/python/sendkeys/

Use SendKeys, for example the key string for Alt-F would be "%F"

An example from the above UR which starts notepad then types "Hello World!"L:
import SendKeys
SendKeys.SendKeys("""
    {LWIN}
    {PAUSE .25}
    r
    Notepad.exe{ENTER}
    {PAUSE 1}
    Hello{SPACE}World!
    {PAUSE 1}
    %{F4}
    n
""")

Open in new window

0
 
myang999Author Commented:
Thanks. It works fine.
Just one thing.
If the application was opened already, how can I bring the focus to the app?
In this case, NotePad.

Thanks.
0
 
myang999Author Commented:
Thank you very much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.