use std::time::Duration;
use crate::error::Result;
use crate::types::Button;
use crate::device::Device;
impl Device {
pub fn click(&self, button: Button, hold: Duration) -> Result<()> {
self.button_down(button)?;
std::thread::sleep(hold);
self.button_up(button)
}
pub fn click_sequence(
&self,
button: Button,
hold: Duration,
count: u32,
interval: Duration,
) -> Result<()> {
for i in 0..count {
self.click(button, hold)?;
if i + 1 < count {
std::thread::sleep(interval);
}
}
Ok(())
}
}
#[cfg(feature = "async")]
use crate::device::AsyncDevice;
#[cfg(feature = "async")]
impl AsyncDevice {
pub async fn click(&self, button: Button, hold: Duration) -> Result<()> {
self.button_down(button).await?;
tokio::time::sleep(hold).await;
self.button_up(button).await
}
pub async fn click_sequence(
&self,
button: Button,
hold: Duration,
count: u32,
interval: Duration,
) -> Result<()> {
for i in 0..count {
self.click(button, hold).await?;
if i + 1 < count {
tokio::time::sleep(interval).await;
}
}
Ok(())
}
}