Skip to content

Commit

Permalink
Use sleep millis
Browse files Browse the repository at this point in the history
  • Loading branch information
XX committed Mar 10, 2019
1 parent 98b53eb commit 341cbcc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ fn main() {
system::init();
env_logger::init();

println!("Start key logging");

let config = parse_args();
debug!("Config: {:?}", config);

Expand Down
8 changes: 6 additions & 2 deletions src/system/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use kernel32;

use crate::{Config, system::{PressEvent, Key, WinKey}};

pub fn init() {}
pub fn init() {
// unsafe { kernel32::FreeConsole() };
}

type VkCode = usize;

Expand Down Expand Up @@ -182,6 +184,7 @@ pub struct InputDevice {
order: KeyPressOrder,
events: VecDeque<(PressEvent, Vk, DateTime<Local>)>,
current_key: String,
sleep_millis: u32,
}

impl InputDevice {
Expand All @@ -190,6 +193,7 @@ impl InputDevice {
order: KeyPressOrder::new(),
events: VecDeque::new(),
current_key: String::new(),
sleep_millis: 1,
}
}

Expand Down Expand Up @@ -219,7 +223,7 @@ impl InputDevice {

pub fn sleep(&self) {
if self.events.is_empty() {
unsafe { kernel32::SleepEx(1, 1); }
unsafe { kernel32::SleepEx(self.sleep_millis, 1); }
}
}
}

0 comments on commit 341cbcc

Please sign in to comment.