Skip to content

Commit

Permalink
Add is used
Browse files Browse the repository at this point in the history
  • Loading branch information
XX committed Feb 19, 2019
1 parent a9f4803 commit 7e25299
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/system/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ impl Vk {
fn is_pressed(&self) -> bool {
(unsafe { user32::GetAsyncKeyState(self.0 as i32) } == -32767)
}

fn is_used(&self) -> bool {
match self.0 as i32 {
0...7 => false,
// Because used VK_L../VK_R.. versions
winuser::VK_CONTROL | winuser::VK_SHIFT | winuser::VK_MENU => false,
_ => true,
}
}
}

pub struct InputDevice {
Expand All @@ -60,15 +69,17 @@ impl InputDevice {
pub fn check_key_event(&mut self) -> Option<(PressEvent, &str, DateTime<Local>)> {
for i in Vk::range() {
let vk = Vk(i);
if vk.is_pressed() {
if !self.pressed_keys[i] {
self.pressed_keys[i] = true;
self.events.push_back((PressEvent::Press, vk, Local::now()));
}
} else {
if self.pressed_keys[i] {
self.pressed_keys[i] = false;
self.events.push_back((PressEvent::Release, vk, Local::now()));
if vk.is_used() {
if vk.is_pressed() {
if !self.pressed_keys[i] {
self.pressed_keys[i] = true;
self.events.push_back((PressEvent::Press, vk, Local::now()));
}
} else {
if self.pressed_keys[i] {
self.pressed_keys[i] = false;
self.events.push_back((PressEvent::Release, vk, Local::now()));
}
}
}
}
Expand Down

0 comments on commit 7e25299

Please sign in to comment.