keyboard.sendkeys(keys)

Sends virtual key presses to other applications.

Parameters

keys

A string that contains one or more key codes/commands combination.

Key codes

Key Code
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 {INS}
LEFT   ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE   DOWN {PGDN}
PAGE UP {PGUP}
PRINT   SCREEN {PRTSC}   (reserved for future use)
RIGHT   ARROW {RIGHT}
SCROLL   LOCK {SCROLL}
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}
Keypad   add {ADD}
Keypad   subtract {SUBTRACT}
Keypad   multiply {MULTIPLY}
Keypad   divide {DIVIDE}
+ {PLUS}
@ {AT}
APPS {APPS}
^ {CARET}
~ {TILDE}
{ } {LEFTBRACE}   {RIGHTBRACE}
( ) {LEFTPAREN}   {RIGHTPAREN}
Left/Right   WINKEY {LWIN}   {RWIN}
WINKEY {WIN}   equivalent to {LWIN}
WINKEY @
SHIFT +
CTRL ^
ALT %

Commands

Command Description
{VKEY X} Sends the VKEY of value X.
Very useful to add new Vkey to the hardcoded previous keys table.
For example, {VKEY 13} is equivalent to VK_RETURN.
{BEEP X Y} Beeps with a frequency of X and a duration of Y milliseconds.
{DELAY X} Delays sending the next key of X milliseconds. After the delaying the following key, the subsequent keys will not be further delayed unless there is a default delay value (see DELAY=X).
Example: {DELAY 1000} <-- delays subsequent key stroke for 1 second.
{DELAY=X} Sets the default delay value to X milliseconds. This will cause every key to be delayed X ms.
If a value is already set and you specify {DELAY Y} you will have your following key delay Y ms but the subsequent keys will be delayed X ms.
Example: {DELAY=1000} <-- all subsequent keys will be delayed for 1 second.
{APPACTIVATE WindowTitle} Activates an application using is WindowTitle.
Very useful if you want to send different keys to different applications.

Return value

This function true if the key/command sequence has been successfully sended, or false otherwise.

Example

local kb = require "keyboard" -- Send virtual keys to launch the Windows Run... command -- then types "notepad", presses Enter, and enters slowly the letters Hello LuaRT ! print(kb.sendkeys("{DELAY=100}@rnotepad{ENTER}{DELAY=600}H{DELAY=100}ello LuaRT !"))