pub struct Keyboard { /* private fields */ }Expand description
Keyboard controller for direct keyboard input.
Provides methods for pressing keys, typing text, and managing modifier state.
§Example
// Press a single key
page.keyboard().press("Enter").await.unwrap();
// Type text character by character
page.keyboard().type_text("Hello").await.unwrap();
// Use key combinations
page.keyboard().press("Control+a").await.unwrap();
// Hold modifier and press keys
page.keyboard().down("Shift").await.unwrap();
page.keyboard().press("a").await.unwrap(); // Types 'A'
page.keyboard().up("Shift").await.unwrap();Implementations§
Source§impl Keyboard
impl Keyboard
Sourcepub fn press(&self, key: &str) -> KeyboardPressBuilder<'_>
pub fn press(&self, key: &str) -> KeyboardPressBuilder<'_>
Press and release a key or key combination.
Returns a builder that can be configured with additional options, or awaited directly for a simple key press.
§Arguments
key- Key to press. Can be:- A single key:
"Enter","a","F1" - A key combination:
"Control+c","Shift+Tab" ControlOrMetafor cross-platform shortcuts
- A single key:
Sourcepub async fn down(&self, key: &str) -> Result<(), LocatorError>
pub async fn down(&self, key: &str) -> Result<(), LocatorError>
Press and hold a key.
The key will remain pressed until up() is called.
Sourcepub async fn type_text(&self, text: &str) -> Result<(), LocatorError>
pub async fn type_text(&self, text: &str) -> Result<(), LocatorError>
Type text character by character with key events.
This generates individual key events for each character.
Use insert_text() for faster text entry without key events.
Sourcepub async fn type_text_with_delay(
&self,
text: &str,
delay: Option<Duration>,
) -> Result<(), LocatorError>
pub async fn type_text_with_delay( &self, text: &str, delay: Option<Duration>, ) -> Result<(), LocatorError>
Type text with a delay between each character.
Sourcepub async fn insert_text(&self, text: &str) -> Result<(), LocatorError>
pub async fn insert_text(&self, text: &str) -> Result<(), LocatorError>
Insert text directly without generating key events.
This is faster than type_text() and works with non-ASCII characters.
No keydown/keyup events are dispatched.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Keyboard
impl !RefUnwindSafe for Keyboard
impl Send for Keyboard
impl Sync for Keyboard
impl Unpin for Keyboard
impl !UnwindSafe for Keyboard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more