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.