Dorian Zedler
9645fb0052
All checks were successful
continuous-integration/drone/push Build is passing
46 lines
1.2 KiB
Rust
46 lines
1.2 KiB
Rust
use std::fmt::{Display, Formatter};
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
|
|
pub enum ContinueButton {
|
|
Tab,
|
|
Enter
|
|
}
|
|
|
|
impl Display for ContinueButton {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "{:?}", self)
|
|
}
|
|
}
|
|
|
|
#[cfg(target_family = "unix")]
|
|
use enigo::{KeyboardControllable};
|
|
|
|
#[cfg(target_family = "unix")]
|
|
pub fn type_text(text: &str) -> Result<(),()> {
|
|
enigo::Enigo::default().key_sequence(text);
|
|
Ok(())
|
|
}
|
|
|
|
#[cfg(target_family = "unix")]
|
|
pub fn click_button(button: ContinueButton) -> Result<(),()> {
|
|
let button = match button {
|
|
ContinueButton::Tab => enigo::Key::Tab,
|
|
ContinueButton::Enter => enigo::Key::Return,
|
|
};
|
|
enigo::Enigo::default().key_click(button);
|
|
Ok(())
|
|
}
|
|
|
|
#[cfg(target_family = "windows")]
|
|
pub fn type_text(text: &str) -> Result<(),()>{
|
|
simulate::type_str(text).map_err(|_| ())
|
|
}
|
|
|
|
#[cfg(target_family = "windows")]
|
|
pub fn click_button(button: ContinueButton) -> Result<(),()> {
|
|
let button = match button {
|
|
ContinueButton::Tab => simulate::Key::Tab,
|
|
ContinueButton::Enter => simulate::Key::Enter,
|
|
};
|
|
simulate::send(button).map_err(|_| ())
|
|
} |