Examples and supported key codes
Simulate pressing the HOME key
key.press("HOMEBUTTON")
Simulate long-pressing the HOME key
key.down("HOMEBUTTON") -- press the HOME key
sys.msleep(1000) -- wait 1 second
key.up("HOMEBUTTON") -- release the HOME key
Simulate double-clicking the HOME key
key.press("HOMEBUTTON")
key.press("HOMEBUTTON")
Simulate pressing the Lock (power) key
key.press("LOCK")
Simulate pressing the Return key
key.press("RETURN")
Other simulations
-- The example below simulates the shortcut [Command + V] to paste clipboard text
-- (it's Command on iOS, not Control on Windows)
key.down("LEFTCOMMAND") -- press Command
sys.msleep(30) -- wait 30 ms
key.press("V") -- press V
sys.msleep(30) -- wait 30 ms
key.up("LEFTCOMMAND") -- release Command
--
-- The example below simulates Command + [ to go back
key.down("LEFTCOMMAND") -- press Command
sys.msleep(30) -- wait 30 ms
key.press("[") -- press [
sys.msleep(30) -- wait 30 ms
key.up("LEFTCOMMAND") -- release Command
--
-- The example below simulates [Command + A] select-all, then Backspace to delete
key.down('LEFTCOMMAND')
sys.msleep(30) -- wait 30 ms
key.press('A') -- press A
sys.msleep(30) -- wait 30 ms
key.up('LEFTCOMMAND')
sys.msleep(100) -- wait 100 ms
key.press('BACKSPACE') -- press Backspace
--
--
key.press("VOLUMEUP") -- press Volume +
key.press("VOLUMEDOWN") -- press Volume -
--
key.down("VOLUMEUP") -- press and hold Volume +
sys.msleep(1000) -- wait 1 second
key.up("VOLUMEUP") -- release Volume +
--
key.down("LOCK") -- press and hold Lock (power)
sys.msleep(3000) -- wait 3 seconds
key.up("LOCK") -- release Lock (power)
--
key.press("SHOW_HIDE_KEYBOARD") -- press [Show/Hide Keyboard] to hide the on-screen keyboard
--
key.press("SHOW_HIDE_KEYBOARD") -- press [Show/Hide Keyboard] again to show the on-screen keyboard
--
-- The example below simulates [Lock + HOME] to take a screenshot to the photo album
key.down("LOCK") -- press Lock (power)
sys.msleep(100) -- wait 100 ms
key.press("HOMEBUTTON") -- press HOME
sys.msleep(100) -- wait 100 ms
key.up("LOCK") -- release Lock (power)
--
-- iOS 7/8 input method switch shortcut
key.down("LEFTCOMMAND")
sys.msleep(50)
key.press(" ")
sys.msleep(50)
key.up("LEFTCOMMAND")
--
-- iOS 9 input method switch shortcut
key.down("LEFTCONTROL")
sys.msleep(50)
key.press("SPACE")
sys.msleep(50)
key.up("LEFTCONTROL")
Note: The above code uses a function not in this chapter: sys.msleep
Supported key codes
-- Letters:
"A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"
--
-- Digits:
"1" "2" "3" "4" "5" "6" "7" "8" "9" "0"
--
-- Function keys:
"F1" "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10" "F11" "F12"
--
-- Other keys:
"RETURN" --< Return
"ESCAPE" --< Esc
"BACKSPACE" --< Backspace
"TAB" --< Tab
"SPACE" --< Space
"HYPHEN" --< "-" or "_"
"EQUAL" --< "=" or "+"
"BRACKETOPEN" --< "[" or "{"
"BRACKETCLOSE" --< "]" or "}"
"BACKSLASH" --< "\\" or "|"
"SEMICOLON" --< ";" or ":"
"QUOTATION" --< Single-quote or double-quote
"ACCENT" --< "`" or "~"
"COMMA" --< "," or "<"
"DOT" --< "." or ">"
"SLASH" --< "/" or "?"
"CAPSLOCK" --< Caps Lock
"PAUSE"
"INSERT"
"HOME" --< Not exactly the HOME key on iOS devices
"PAGEUP"
"DELETE"
"END"
"PAGEDOWN"
"RIGHTARROW" --< Right arrow
"LEFTARROW" --< Left arrow
"DOWNARROW" --< Down arrow
"UPARROW" --< Up arrow
"LEFTCONTROL" --< Left Ctrl
"LEFTSHIFT" --< Left Shift
"LEFTALT" --< Left Alt
"LEFTCOMMAND" --< Left Command
"RIGHTCONTROL" --< Right Ctrl
"RIGHTSHIFT" --< Right Shift
"RIGHTALT" --< Right Alt
"RIGHTCOMMAND" --< Right Command
"LOCK" --< Lock (power)
"HOMEBUTTON" --< This is the HOME key on iOS devices
"FORWARD" --< Media next
"REWIND" --< Media previous
"FORWARD2" --< Media next 2
"REWIND2" --< Media previous 2
"EJECT"
"PLAYPAUSE" --< Media pause
"MUTE" --< Mute
"VOLUMEUP" --< Volume +
"VOLUMEDOWN" --< Volume -
"SPOTLIGHT" --< Spotlight
"BRIGHTUP" --< Brightness +
"BRIGHTDOWN" --< Brightness -
"SHOW_HIDE_KEYBOARD" --< Show/Hide keyboard