Skip to content

I.press()

Presses a key or a combination of keys.

This will send the keyboard input to the active element (or the <body> element if no element is in focus).

Keys are released at the end of the command.

Usage

js
I.press(key: string | string[])

Convenience key commands

UI-licious provides convenience commands for commonly used special keys.

js
I.pressEnter() // press the "Enter" key

I.pressTab()   // press the "Tab" key

I.pressUp()    // press the Up arrow key
I.pressDown()  // press the Down arrow key
I.pressLeft()  // press the Left arrow key
I.pressRight() // press the Right arrow key

Parameters

ParameterTypeDescription
keystring | string[]The key or keys to press

Examples

Press a Key

js
I.press("a")

This sends the letter "a" keyboard input to the active element.

Press a special key

To press special keys, use I.press() with the name of the key:

js
// enter key
I.press("Enter")

// delete and backspace
I.press("Delete")
I.press("Backspace")

// escape key
I.press("Escape")

// tab
I.press("Tab")

// arrow keys
I.press("ArrowUp")
I.press("ArrowDown")
I.press("ArrowLeft")
I.press("ArrowRight")

// modifier keys
I.press("Shift")
I.press("Control")
I.press("Alt")
I.press("Meta")

Press a Chord (send multiple keys simultaneously)

You can use an array to press multiple keys at the same time.

For example, to press "Control" + "a" to select all text:

js
I.press(["Control", "a"])

Pressing "Control" + "c" to copy selected text:

js
I.press(["Control", "c"])

Pressing "Control" + "v" to paste content from the clipboard:

js
I.press(["Control", "v"])