Example of sending a control key using python in windows

Source: Internet
Author: User

In windows, when using python for graphics operations, you often need to send shortcuts, such as ALT + TAB, crtl + F1, Fn + f1, and other operations. Using the win32com module, this type of operation is very convenient. For example, the following example is an example of opening the Outlook program, obtaining the first element, and copying its content to the clipboard:

Import win32com. client
Shell = win32com. client. Dispatch ("WScript. Shell ")
Shell. Run ("outlook ")
Shell. AppActivate ("Outlook ")
Shell. SendKeys ("^ o", 0)
Shell. SendKeys ("^ a", 0)
Shell. SendKeys ("^ c", 0)

Some key ing relationships are as follows:

 


















































































































Key

Argument

BACKSPACE

{BACKSPACE}, {BS}, or {BKSP}

BREAK

{BREAK}

CAPS LOCK

{CAPSLOCK}

DEL or DELETE

{DELETE} or {DEL}

DOWN ARROW

{DOWN}

END

{END}

ENTER

{ENTER} or ~

ESC

{ESC}

HELP

{HELP}

HOME

{HOME}

INS or INSERT

{INSERT} or {INS}

LEFT ARROW

{LEFT}

NUM LOCK

{NUMLOCK}

PAGE DOWN

{PGDN}

PAGE UP

{PGUP}

PRINT SCREEN

{PRTSC}

RIGHT ARROW

{RIGHT}

SCROLL LOCK

{SCROLLLOCK}

TAB

{TAB}

UP ARROW

{UP}

F1

{F1}

F2

{F2}

F3

{F3}

F4

{F4}

F5

{F5}

F6

{F6}

F7

{F7}

F8

{F8}

F9

{F9}

F10

{F10}

F11

{F11}

F12

{F12}

F13

{F13}

F14

{F14}

F15

{F15}

F16

{F16}

 

The following table lists the key-to-key mappings:

 


















Key

Special Character

SHIFT

+

CTRL

^

ALT

%

ENTER

~

 

Through the above ing relationship table, such as pressing ctrl + F5 to force refresh the browser page is easier to achieve, shell. SendKeys ("^ {F5}", 0.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.