?
Solved

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

Posted on 2008-11-17
4
Medium Priority
?
2,178 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:myang999
  • 2
4 Comments
 

Expert Comment

by:_jMerliN_
ID: 22977956
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
 

Author Comment

by:myang999
ID: 22978260
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
 
LVL 7

Accepted Solution

by:
jdpipe earned 2000 total points
ID: 23001629
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
 

Author Closing Comment

by:myang999
ID: 31517531
Thank you very much.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Article by: Swadhin
Introduction of Lists in Python: There are six built-in types of sequences. Lists and tuples are the most common one. In this article we will see how to use Lists in python and how we can utilize it while doing our own program. In general we can al…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month16 days, 18 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question