Skip to content

Commit

Permalink
Add support for setting modifier delay in key.tap()
Browse files Browse the repository at this point in the history
  • Loading branch information
msanders committed Oct 23, 2019
1 parent 5e14707 commit a6ea362
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,19 @@ fn toggle(
/// Convenience wrapper around `toggle()` that holds down and then releases
/// the given key and modifiers.
#[pyfunction]
fn tap(key: &PyAny, modifiers: Vec<&Modifier>, delay: Option<f64>) -> PyResult<()> {
fn tap(
key: &PyAny,
modifiers: Vec<&Modifier>,
delay: Option<f64>,
modifier_delay: Option<f64>,
) -> PyResult<()> {
let delay_ms: u64 = delay.map(|x| x as u64 * 1000).unwrap_or(0);
let modifier_delay_ms: u64 = modifier_delay.map(|x| x as u64 * 1000).unwrap_or(delay_ms);
if let Some(either) = py_object_to_key_code_convertible(key) {
let flags: Vec<_> = modifiers.iter().map(|x| x.flag).collect();
match either {
Left(x) => autopilot::key::tap(&x, &flags, delay_ms, delay_ms),
Right(x) => autopilot::key::tap(&x, &flags, delay_ms, delay_ms),
Left(x) => autopilot::key::tap(&x, &flags, delay_ms, modifier_delay_ms),
Right(x) => autopilot::key::tap(&x, &flags, delay_ms, modifier_delay_ms),
};
Ok(())
} else {
Expand Down

0 comments on commit a6ea362

Please sign in to comment.