Keyboard input emulation module

Automate typing keys or individual key actions (viz. press and hold, release) to an active window by calling send_keys method.

You can use any Unicode characters (on Windows) and some special keys listed below. The module is also available on Linux.

Available key codes:

{BACK}, {VK_HOME}, {F23}, {F22}, {F21}, {F20}, {VK_HANGEUL}, {VK_KANJI},
{VK_PA1}, {VK_NONAME}, {VK_LCONTROL}, {ZOOM}, {VK_ATTN}, {VK_F10}, {VK_F22},
{VK_F23}, {VK_F20}, {VK_F21}, {VK_SCROLL}, {TAB}, {VK_F11}, {VK_END},
{F3}, {F4}, {F5}, {F6}, {F7}, {F8}, {F9}, {VK_ADD}, {VK_RCONTROL},
{RMENU}, {VK_F3}, {VK_F2}, {VK_F1}, {VK_F7}, {VK_F6}, {VK_F5}, {VK_CRSEL},
{F18}, {F19}, {ESC}, {VK_MULTIPLY}, {F12}, {F13}, {F10}, {F11}, {F16},
{F17}, {F14}, {F15}, {F24}, {RIGHT}, {VK_F24}, {VK_CAPITAL}, {VK_LBUTTON},
{VK_F19}, {VK_EXECUTE}, {VK_PLAY}, {VK_RMENU}, {VK_F13}, {VK_F12}, {LWIN},
{VK_DOWN}, {VK_F17}, {VK_F16}, {VK_F15}, {VK_F14}

~ is a shorter alias for {ENTER}


  • '+': {VK_SHIFT}
  • '^': {VK_CONTROL}
  • '%': {VK_MENU} a.k.a. Alt key

Example how to use modifiers:

send_keys('^a^c') # select all (Ctrl+A) and copy to clipboard (Ctrl+C)
send_keys('+{INS}') # insert from clipboard (Shift+Ins)
send_keys('%{F4}') # close an active window with Alt+F4

Repetition count can be specified for special keys. {ENTER 2} says to press Enter twice.

Example which shows how to press and hold or release a key on the keyboard:

send_keys("{VK_SHIFT down}"
          "{VK_SHIFT up}") # to type PYWINAUTO

send_keys("{h down}"
          "{e down}"
          "{h up}"
          "{e up}"
          "llo") # to type hello

Use curly brackers to escape modifiers and type reserved symbols as single keys:

send_keys('{^}a{^}c{%}') # type string "^a^c%" (Ctrl will not be pressed)
send_keys('{{}ENTER{}}') # type string "{ENTER}" without pressing Enter key