Skip to content

Keyboard

Using the methods below, you can control and obtain information from the keyboard.

Writing text

You can write text in a couple of different ways depending on the behaviour that you want to simulate.

Human-like typing

Using this method you can simulate a human typing text key by key.

# 'kb_type' method receives text to be typed.
bot.kb_type("This is a exemple using 'kb_type' method")
// 'kbType' method receives text to be typed.
kbType("This is a exemple using 'kbType' method");

Pasting the text all at once

The paste method is fast and widely used but the difference is that it just pastes the contents of the clipboard.

Tip

Some fields such as selection boxes (ComboBox widgets) or some web forms don't allow the paste operation. To overcome issues like that, use the Human-like method described above.

# 'paste' method receives text to be pasted.
bot.paste("This is a exemple using 'paste' method")
// 'paste' method uses clipboard content.
paste();

// 'type' method receives text to be typed.
type("This is a exemple using 'type' method");

Pressing keyboard keys

You can press keys on the keyboard to activate shortcuts and perform other operations.

Tab

The tab method press key Tab of keyboard.

# Press tab key.
bot.tab()
// Press tab key.
tab();

Enter

The enter method press the key Enter on the keyboard.

Tip

This method can often be used to replace a click or interaction with a button through computer vision.

# Press enter key.
bot.enter()
// Press enter key.
enter();

Escape/Esc

# Press Esc key.
bot.key_esc()
// Press Esc key.
keyEsc();

Space

# Press space key.
bot.space()
// Press space key.
space();

Backspace

# Press backspace key.
bot.backspace()
// Press backspace key.
backspace();

Delete

# Press Delete key.
bot.delete()
// Press Delete key.
delete();

Shift

The Shift key can be held down and released as to simulate a magnitude of behaviours depending on the process that you are automating.

To demonstrate, we are going to hold the Shift key and type a text to make the text uppercase. We will also release the Shift key and type the same text in lowercase.

# Press and hold shift.
bot.hold_shift()

# Type the text "test", noting that the text is rendered in uppercase.
bot.type_key("test uppercase")

# Realese shift.
bot.release_shift()

# take a space to type new text.
bot.space(wait=1000)

# Type the text "test", noting that the text is rendered in lowercase, because was used the method  release shift earlier.
bot.type_key("test lowercase")
// Press and hold shift.
holdShift();

// Type the text "test", noting that the text is rendered in uppercase.
type("test uppercase");

// Realese shift.
releaseShift();

// take a space to type new text.
space(1000);

// Type the text "test", noting that the text is rendered in lowercase, because was used the method release shift earlier.
type("test lowercase");

Directional keys

With the methods below, we can interact, or press the keyboard directional keys (up, down, left and right).

# On the directional keyboard, press the up key, up arrow.
bot.type_up()

# On the directional keyboard, press the down key, down arrow.
bot.type_down()

# On the directional keyboard, press the left key, left arrow.
bot.type_left()

# On the directional keyboard, press the right key, right arrow.
bot.type_right()
// the directional keyboard, press the up key, up arrow.
typeUp();

// On the directional keyboard, press the down key, down arrow.
typeDown();

// On the directional keyboardd, press the Left key, Left arrow.
typeLeft();

// On the directional keyboard, press the right key, right arrow.
typeRight();

Page Up and Page Down

# Press page up key, making the page scroll up.
bot.page_up()

# Press page up key, making the page scroll down.
bot.page_down()
// Press up key, making the page scroll up.
pageUp();

// Press down key, making the page scroll down.
pageDown();

Keyboard shortcuts

The framework has the most used shortcuts ready to use.

In the event that we missed one you can use the type keys method to press any list of keys and simulate any shortcut.

Warning

You must use keys and shortcuts that are compatible with the browser context.

Using type keys for shortcuts

# Pressing keys in sequence.
bot.type_keys(["a", "b", "c"])

# Pressing keys in sequence with interval in which to press and release keys.
bot.type_keys_with_interval(interval=2000, keys=["a", "b", "c"])
// Pressing keys in sequence.
typeKeys("a", "b", "c");

You can also pass the key reference you need to use via Selenium's Keys class.

from selenium.webdriver.common.keys import Keys

# Pressing keys in sequence.
bot.type_keys([Keys.CONTROL, Keys.ALT, "c"])
import org.openqa.selenium.Keys;

// Pressing keys in sequence.
typeKeys(Keys.CONTROL, Keys.ALT, "c");

Shortcut with Control

# Pressing 'Ctrl + c' to copy clipboard.
bot.control_c()

# Pressing 'Ctrl + v' to paste content.
bot.control_v()

# Pressing 'Ctrl + a' to select all content.
bot.control_a()
// Pressing 'Ctrl + c' to copy clipboard.
controlC();

// Pressing 'Ctrl + v' to paste content.
controlV();

// Pressing 'Ctrl + a' to select all content.
controlA();