Table Of Contents

Previous topic

Finder

Next topic

Sikuli Best Practice

This Page

Key Constants

class Key

Applicable usage situations for these predefined constants of special keys and key modifiers can be found in Acting on a Region and Low Level Mouse and Keyboard Actions.

Special Keys

The methods supporting the use of special keys are type(), keyDown(), and keyUp().

Usage: Key.CONSTANT (where CONSTANT is one of the following key names).

String concatenation with with other text or other key constants is possible using “+”.

type("some text" + Key.TAB + "more text" + Key.TAB + Key.ENTER)
# or eqivalent
type("some text\tmore text\n")

miscellanous keys

ENTER, TAB, ESC, BACKSPACE, DELETE, INSERT

New in version X1.0-rc3.

miscellanous keys

SPACE

function keys

F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15

navigation keys

HOME, END, LEFT, RIGHT, DOWN, UP, PAGE_DOWN, PAGE_UP

special keys

PRINTSCREEN, PAUSE, CAPS_LOCK, SCROLL_LOCK, NUM_LOCK

New in version X1.0-rc2.

Note: The status ( on / off ) of the keys Key.CAPS_LOCK, Key.NUM_LOCK and Key.SCROLL_LOCK can be evaluated with the method Env.isLockOn().

numpad keys

NUM0, NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9
SEPARATOR, ADD, MINUS, MULTIPLY, DIVIDE

modifier keys

ALT, CMD, CTRL, META, SHIFT, WIN

These modifier keys cannot be used as a key modifier with functions like type(), rightClick(), etc. They can only be used with keyDown() and keyUp(). If you need key modifiers, use KeyModifier instead.

Key Modifiers

Methods where key modifiers can be used include: click(), dragDrop() , doubleClick() , rightClick(), type().

Deprecated since version X1.0-rc3.

the oldies but goldies

KEY_ALT, KEY_CTRL, KEY_SHIFT

system specific Win/Mac

KEY_WIN, KEY_CMD
KEY_META (a synonym for KEY_WIN or KEY_CMD on Windows and Mac respectively).

The old modifiers with a KEY_ prefix are deprecated. Use KeyModifier.CTRL, KeyModifier.ALT, KeyModifier.SHIFT, KeyModifier.META instead.

New in version X1.0-rc3.

class KeyModifier

Usage: KeyModifier.CONSTANT (where CONSTANT is one of the following key names).

CTRL
equivalent to the old KEY_CTRL
SHIFT
equivalent to the old KEY_SHIFT
ALT
equivalent to the old KEY_ALT
META
equivalent to the old KEY_META
CMD
equivalent to the old KEY_CMD (and KEY_META)
WIN
equivalent to the old KEY_WIN (and KEY_META)

The modifier constants can be combined to the modifier parameter by either using “+” or “|”, if more than one key modifier is needed.

type(Key.ESC, KeyModifier.CTRL + KeyModifier.ALT)
# or equivalent
type(Key.ESC, KeyModifier.CTRL | KeyModifier.ALT)

They should only be used in the modifiers parameter with functions like type(), rightClick(), etc.

They should never be used with keyDown() or keyUp().

Note for Java programming: These constants are mapped to the according constants of the Java environment in the class java.awt.event.InputEvent.