class Playwright::Keyboard
“‘
page.keyboard.press(“Meta+A”)
# on mac_os
page.keyboard.press(“Control+A”)
# on windows and linux
“`python sync
An example to trigger select-all with the keyboard
“`
page.keyboard.press(“Shift+A”)
# or
page.keyboard.press(“Shift+KeyA”)
“`python sync
An example of pressing uppercase `A`
“`
# result text will end up saying “Hello!”
page.keyboard.press(“Backspace”)
page.keyboard.up(“Shift”)
page.keyboard.press(“ArrowLeft”)
for i in range(6):
page.keyboard.down(“Shift”)
page.keyboard.press(“ArrowLeft”)
page.keyboard.type(“Hello World!”)
“`python sync
An example of holding down `Shift` in order to select and delete some text:
to manually fire events as if they were generated from a real keyboard.
For finer control, you can use [`method: Keyboard.down`], [`method: Keyboard.up`], and [`method: Keyboard.insertText`]
raw characters and generates proper `keydown`, `keypress`/`input`, and `keyup` events on your page.
Keyboard provides an api for managing a virtual keyboard. The high level api is [`method: Keyboard.type`], which takes
def down(key)
[`method: Keyboard.up`].
[repeat](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat) set to true. To release the key, use
After the key is pressed once, subsequent calls to [`method: Keyboard.down`] will have
modifier active. To release the modifier key, use [`method: Keyboard.up`].
If `key` is a modifier key, `Shift`, `Meta`, `Control`, or `Alt`, subsequent key presses will be sent with that
respective texts.
If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different
Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
`Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
`F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
[here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
generate the text for. A superset of the `key` values can be found
[keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) value or a single character to
`key` can specify the intended
Dispatches a `keydown` event.
def down(key) wrap_impl(@impl.down(unwrap_impl(key))) end
def insert_text(text)
```
page.keyboard.insert_text("嗨")
```python sync
**Usage**
Dispatches only `input` event, does not emit the `keydown`, `keyup` or `keypress` events.
def insert_text(text) wrap_impl(@impl.insert_text(unwrap_impl(text))) end
def press(key, delay: nil)
```
browser.close()
page.screenshot(path="o.png")
page.keyboard.press("Shift+O")
page.screenshot(path="arrow_left.png")
page.keyboard.press("ArrowLeft")
page.screenshot(path="a.png")
page.keyboard.press("a")
page.goto("https://keycode.info")
page = browser.new_page()
```python sync
**Usage**
modifier, modifier is pressed and being held while the subsequent key is being pressed.
Shortcuts such as `key: "Control+o"`, `key: "Control++` or `key: "Control+Shift+T"` are supported as well. When specified with the
respective texts.
If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different
Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
`Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
`F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
[here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
generate the text for. A superset of the `key` values can be found
[keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key) value or a single character to
`key` can specify the intended
**NOTE**: In most cases, you should use [`method: Locator.press`] instead.
def press(key, delay: nil) wrap_impl(@impl.press(unwrap_impl(key), delay: unwrap_impl(delay))) end
def type(text, delay: nil)
**NOTE**: Modifier keys DO NOT effect `keyboard.type`. Holding down `Shift` will not type the text in upper case.
```
page.keyboard.type("World", delay=100) # types slower, like a user
page.keyboard.type("Hello") # types instantly
```python sync
**Usage**
To press a special key, like `Control` or `ArrowDown`, use [`method: Keyboard.press`].
Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text.
**NOTE**: In most cases, you should use [`method: Locator.fill`] instead. You only need to press keys one by one if there is special keyboard handling on the page - in this case use [`method: Locator.pressSequentially`].
def type(text, delay: nil) wrap_impl(@impl.type(unwrap_impl(text), delay: unwrap_impl(delay))) end
def up(key)
def up(key) wrap_impl(@impl.up(unwrap_impl(key))) end