Link to home
Start Free TrialLog in
Avatar of myang999
myang999Flag for United States of America

asked on

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.
Avatar of _jMerliN_
_jMerliN_

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

Avatar of myang999

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of jdpipe
jdpipe
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much.