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 async fn press(&self, key: &str) -> Result<(), LocatorError>
pub async fn press(&self, key: &str) -> Result<(), LocatorError>
Press and release a key or key combination.
§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:
§Example
ⓘ
page.keyboard().press("Enter").await?;
page.keyboard().press("Control+a").await?;
page.keyboard().press("ControlOrMeta+c").await?;Sourcepub async fn press_with_delay(
&self,
key: &str,
delay: Option<Duration>,
) -> Result<(), LocatorError>
pub async fn press_with_delay( &self, key: &str, delay: Option<Duration>, ) -> Result<(), LocatorError>
Press and release a key with a delay between down and up.
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>
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