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
use viewpoint_core::Page;
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 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.
§Example
use viewpoint_core::Page;
page.keyboard().down("Shift").await?;
page.keyboard().press("a").await?; // Types 'A'
page.keyboard().up("Shift").await?;Sourcepub async fn up(&self, key: &str) -> Result<(), LocatorError>
pub async fn up(&self, key: &str) -> Result<(), LocatorError>
Release a held key.
§Example
use viewpoint_core::Page;
page.keyboard().down("Shift").await?;
// ... do stuff with Shift held
page.keyboard().up("Shift").await?;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.
§Example
use viewpoint_core::Page;
page.keyboard().type_text("Hello, World!").await?;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.
§Example
use viewpoint_core::Page;
page.keyboard().insert_text("Hello 👋 你好").await?;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