Skip to content

Commit

Permalink
Update modifiers param in key.tap() and key.toggle() to be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
msanders committed Oct 30, 2019
1 parent 5692e03 commit 1d58f89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/key.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Functions
-----------------------------
.. automodule:: autopy.key

.. autofunction:: toggle(key: Any, down: bool, modifiers: List[Modifier], modifier_delay: float=None)
.. autofunction:: tap(key: Any, modifiers: List[Modifier], delay: float=None)
.. autofunction:: toggle(key: Any, down: bool, modifiers: List[Modifier]=[], modifier_delay: float=None)
.. autofunction:: tap(key: Any, modifiers: List[Modifier]=[], delay: float=None)
.. autofunction:: type_string(string: str, wpm: float=None)


Expand Down
16 changes: 12 additions & 4 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,16 @@ impl _Code {
fn toggle(
key: &PyAny,
down: bool,
modifiers: Vec<&Modifier>,
modifiers: Option<Vec<&Modifier>>,
modifier_delay: Option<u64>,
) -> PyResult<()> {
let modifier_delay_ms: u64 = modifier_delay.map(|x| x as u64 * 1000).unwrap_or(0);
if let Some(either) = py_object_to_key_code_convertible(key) {
let flags: Vec<_> = modifiers.iter().map(|x| x.flag).collect();
let flags: Vec<_> = modifiers
.unwrap_or(Vec::new())
.iter()
.map(|x| x.flag)
.collect();
match either {
Left(x) => autopilot::key::toggle(&x, down, &flags, modifier_delay_ms),
Right(x) => autopilot::key::toggle(&x, down, &flags, modifier_delay_ms),
Expand All @@ -250,14 +254,18 @@ fn toggle(
#[pyfunction]
fn tap(
key: &PyAny,
modifiers: Vec<&Modifier>,
modifiers: Option<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();
let flags: Vec<_> = modifiers
.unwrap_or(Vec::new())
.iter()
.map(|x| x.flag)
.collect();
match either {
Left(x) => autopilot::key::tap(&x, &flags, delay_ms, modifier_delay_ms),
Right(x) => autopilot::key::tap(&x, &flags, delay_ms, modifier_delay_ms),
Expand Down

0 comments on commit 1d58f89

Please sign in to comment.