-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
90 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "ka" | ||
version = "0.6.0" | ||
version = "0.7.0" | ||
edition = "2021" | ||
authors = ["mdpadberg <[email protected]>"] | ||
|
||
|
@@ -13,4 +13,5 @@ rand = "0.8.5" | |
serde_json = "1.0" | ||
serde = { version = "1.0", features = ["derive"] } | ||
dirs = "4.0.0" | ||
anyhow = "1.0.62" | ||
anyhow = "1.0.62" | ||
enigo = "0.0.14" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,45 @@ | ||
//TODO | ||
use std::{thread, time::Duration}; | ||
|
||
use crate::cli::MySubCommand; | ||
use clap::{Arg, Command}; | ||
use enigo::{Enigo, Key, KeyboardControllable}; | ||
|
||
pub struct Keyboard; | ||
|
||
impl MySubCommand for Keyboard { | ||
const NAME: &'static str = "keyboard"; | ||
|
||
fn command() -> clap::Command<'static> { | ||
Command::new(Keyboard::NAME) | ||
.about("Use keyboard to keep your machine awake [default tab & windows/super/command]") | ||
.arg( | ||
Arg::new("interval") | ||
.help("set a time interval in seconds on how often you want to run this") | ||
.long("interval") | ||
.takes_value(true) | ||
.default_value("60"), | ||
) | ||
} | ||
|
||
fn action(args: &clap::ArgMatches) { | ||
let interval = args.get_one::<String>("interval").unwrap(); | ||
let mut enigo = Enigo::new(); | ||
if let Ok(interval) = interval.parse::<u64>() { | ||
loop { | ||
thread::sleep(Duration::from_secs(interval)); | ||
enigo.key_down(Key::Meta); | ||
thread::sleep(Duration::from_millis(200)); | ||
enigo.key_down(Key::Tab); | ||
thread::sleep(Duration::from_millis(200)); | ||
enigo.key_up(Key::Tab); | ||
thread::sleep(Duration::from_millis(200)); | ||
enigo.key_up(Key::Meta); | ||
} | ||
} else { | ||
eprintln!( | ||
"Could not parse interval:{}. Did you configure a valid number?", | ||
interval | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ mod cli; | |
mod mouse; | ||
mod settings; | ||
mod programname; | ||
mod keyboard; | ||
|
||
fn main() { | ||
cli::parse(); | ||
|