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 behavior 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")
// 'type' method receives the text to be typed.
type("This is a exemple using 'type' method");
// 'kbType' method receives text to be typed.
await desktopBot.kbType('This is a exemple using "kbType" method')
// 'kbType' method receives text to be typed.
await desktopBot.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 receives text to be pasted.
paste("This is a exemple using 'paste' method");
// 'paste' method receives text to be pasted.
await desktopBot.paste('This is a exemple using "paste" method')
// 'paste' method receives text to be pasted.
await desktopBot.paste('This is a exemple using "paste" 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 the tab key.
bot.tab()
// Press the tab key.
tab();
// Press the tab key.
await desktopBot.tab()
// Press the tab key.
await desktopBot.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();
// Press enter key.
await desktopBot.enter()
// Press enter key.
await desktopBot.enter()

Escape/Esc

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

Space

# Press the space key.
bot.space()
// Press the space key.
space();
// Press the space key.
await desktopBot.space()
// Press the space key.
await desktopBot.space()

Backspace

# Press the backspace key.
bot.backspace()
// Press the backspace key.
backspace();
// Press the backspace key.
await desktopBot.backspace()
// Press the backspace key.
await desktopBot.backspace()

Delete

# Press the Delete key.
bot.delete()
// Press the Delete key.
delete();
// Press the Delete key.
await desktopBot.delete()
// Press the Delete key.
await desktopBot.delete()

Shift

The Shift key can be held down and released to simulate a magnitude of behaviors depending on the application that you are using.

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");

// Release 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");
// Press and hold shift.
await desktopBot.holdShift()

// Type the text "test", noting that the text is rendered in uppercase.
await desktopBot.typeKeys("test uppercase")

// Release shift.
await desktopBot.releaseShift()

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

// Type the text "test", noting that the text is rendered in lowercase because was used the method release shift earlier.
await desktopBot.typeKeys("test lowercase")
// Press and hold shift
await desktopBot.holdShift()

// Type the text "test", noting that the text is rendered in uppercase.
await desktopBot.typeKeys("test uppercase")

// Realese shift
await desktopBot.releaseShift()

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

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

Win key

# Press Win logo key, and open the start of Windows.
bot.type_windows()
// Press Win logo key, and open the start of Windows.
keyWindows();
// Press the Win logo key, and open the start of Windows.
await desktopBot.typeWindows()
// Press the Win logo key and open the start of Windows.
await desktopBot.typeWindows()

Function Keys

You can activate the Function keys 1 through 12 with the key fn function.

# Press key f5 to trigger the native function of this key, In this case, refreshes pages in most browsers.
bot.key_f5()

# Press key f11, triggers the native function of this key, in this case, it changes the screen to full mode.
bot.key_f11()

# For other keys, use key_fn where n is the number from 1 to 12.
// Press key f5 to trigger the native function of this key, In this case, refreshes pages in most browsers.
keyF5();

// Press key f11, triggers the native function of this key, in this case, it changes the screen to full mode.
keyF11();

// For other keys, use keyFn where n is the number from 1 to 12.
// Press key f5 to trigger the native function of this key, In this case, refreshes pages in most browsers.
await desktopBot.keyF5()

// Press key f11, triggers the native function of this key, in this case, it changes the screen to full mode.
await desktopBot.keyF5()

// For other keys, use keyFn where n is the number from 1 to 12.
// Press key f5 to trigger the native function of this key, In this case, refreshes pages in most browsers.
await desktopBot.keyF5()

// Press key f11, triggers the native function of this key, in this case, it changes the screen to full mode.
await desktopBot.keyF5()

// For other keys, use keyFn where n is the number from 1 to 12.

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.
bot.type_up()

# On the directional keyboard, press the down key.
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.
keyUp();

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

// On the directional keyboard, press the Left key, Left arrow.
keyLeft();

// On the directional keyboard, press the right key, right arrow.
keyRight();
// On the directional keyboard, press the up key, up arrow.
await desktopBot.typeUp()

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

// On the directional keyboard, press the left key, left arrow.
await desktopBot.typeLeft()

// On the directional keyboard, press the right key, right arrow.
await desktopBot.typeRight()
// On the directional keyboard, press the up key, up arrow.
await desktopBot.typeUp()

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

// On the directional keyboard, press the left key, left arrow.
await desktopBot.typeLeft()

// On the directional keyboard, press the right key, right arrow.
await desktopBot.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 the up key, making the page scroll up.
keyUp();

// Press the down key, making the page scroll down.
keyDown();
// Press the up key, making the page scroll up.
await desktopBot.pageUp();

// Press the down key, making the page scroll down.
await desktopBot.pageDown();
// Press the up key, making the page scroll up.
await desktopBot.pageUp();

// Press the down key, making the page scroll down.
await desktopBot.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.

Using type keys for shortcuts

# Pressing the 'win', 'shift', 's' keys in sequence. This shortcut enables capturing the screen in Windows 11.
bot.type_keys(["win", "shift", "s"])

# Pressing the 'win', 'shift', 's' keys in sequence with an interval in which to press and release keys.
bot.type_keys_with_interval(interval=2000, keys=["win", "shift", "s"])
import java.awt.event.KeyEvent;

// Pressing the 'win', 'shift', 's' keys in sequence. This shortcut enables capturing the screen in Windows 11.
typeKeys(KeyEvent.VK_WINDOWS, KeyEvent.VK_SHIFT, KeyEvent.VK_S);

// Pressing the 'win', 'shift', 's' keys in sequence with an interval in which to press and release keys.
typeKeysWithInterval(KeyEvent.VK_WINDOWS, KeyEvent.VK_SHIFT, KeyEvent.VK_S);
// Pressing the 'win', 'shift', 's' keys in sequence. This shortcut enables capturing the screen in Windows 11.
await desktopBot.typeKeys(["win", "shift", "s"])

// Pressing the 'win', 'shift', 's' keys in sequence with an interval in which to press and release keys.
await desktopBot.typeKeys(["win", "shift", "s"], 2000)
// Pressing the 'win', 'shift', 's' keys in sequence. This shortcut enables capturing the screen in Windows 11.
await desktopBot.typeKeys(["win", "shift", "s"])

// Pressing the 'win', 'shift', 's' keys in sequence with an interval in which to press and release keys.
await desktopBot.typeKeys(["win", "shift", "s"], 2000)

Shortcuts with Alt

# Pressing Alt + Space, the keyboard shortcut.
bot.alt_space()
# Pressing Alt + e, the keyboard shortcut.
bot.alt_e()
# Pressing Alt + r, the keyboard shortcut.
bot.alt_r()
# Pressing Alt + f, the keyboard shortcut.
bot.alt_f()
# Pressing Alt + U, the keyboard shortcut.
bot.alt_u()
# Pressing Alt + f4, the keyboard shortcut.
bot.alt_f4()
// Pressing Alt + Space, the keyboard shortcut.
altSpace();
// Pressing Alt + e, keyboard shortcut.
altE();
// Pressing Alt + r,  keyboard shortcut.
altR();
// Pressing Alt + f, keyboard shortcut.
altF();
// Pressing Alt + U, keyboard shortcut.
altU();
// Pressing Alt + f4, keyboard shortcut.
altF4();
// Pressing Alt + Space, the keyboard shortcut.
await desktopBot.altSpace()
// Pressing Alt + e, keyboard shortcut.
await desktopBot.altE()
// Pressing Alt + r,  keyboard shortcut.
await desktopBot.altR()
// Pressing Alt + f, keyboard shortcut.
await desktopBot.altF()
// Pressing Alt + U, keyboard shortcut.
await desktopBot.altU()
// Pressing Alt + f4, keyboard shortcut.
await desktopBot.altF4()
// Pressing Alt + Space, the keyboard shortcut.
await desktopBot.altSpace()
// Pressing Alt + e, keyboard shortcut.
await desktopBot.altE()
// Pressing Alt + r,  keyboard shortcut.
await desktopBot.altR()
// Pressing Alt + f, keyboard shortcut.
await desktopBot.altF()
// Pressing Alt + U, keyboard shortcut.
await desktopBot.altU()
// Pressing Alt + f4, keyboard shortcut.
await desktopBot.altF4()

Shortcuts with Shift

# Pressing Shift + tab, the keyboard shortcut.
bot.shift_tab()
// Pressing Shift + tab, the keyboard shortcut.
shiftTab();
// Pressing Shift + tab, the keyboard shortcut.
await dekstopBot.shiftTab()
// Pressing Shift + tab, the keyboard shortcut.
await dekstopBot.shiftTab()

Shortcut with Control

# Pressing 'Ctrl + c' to copy the 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 + f' to open a search bar.
bot.control_f()

# Pressing 'Ctrl + p' to print the screen.
bot.control_p()
// Pressing 'Ctrl + c' to copy the clipboard.
controlC();

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

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

// Pressing 'Ctrl + f' to open the search bar.
controlF();

// Pressing 'Ctrl + p' to print the screen.
controlP();
// Pressing 'Ctrl + c' to copy the clipboard.
await desktopBot.controlC()

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

// Pressing 'Ctrl + a' to select all content.
await desktopBot.controlA()
// Pressing 'Ctrl + c' to copy the clipboard.
await desktopBot.controlC()

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

// Pressing 'Ctrl + a' to select all content.
await desktopBot.controlA()
Other Ctrl shortcuts

In addition to the methods shown above, we have other shortcuts with control keys that can be used in the same way:

Shortcut
Ctrl+U
Ctrl+R
Ctrl+T
Ctrl+W
Ctrl+End
Ctrl+Home
Ctrl+Shift+J
Ctrl+Shift+P