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.
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.
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.
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.
Escape/Esc¶
Space¶
Backspace¶
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¶
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, 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
¶
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¶
Shortcut with Control¶
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 |