Skip to content

Commit

Permalink
Keep previous key press state
Browse files Browse the repository at this point in the history
  • Loading branch information
davystrong committed Sep 5, 2021
1 parent 8064bed commit 32d2225
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod winapi_functions;
use cli::Opts;
use clipboard_win::{formats, get_clipboard, set_clipboard};
use core::ptr;
use key_utils::is_key_pressed;
use lazy_static::lazy_static;
use std::collections::VecDeque;
use std::ffi::CString;
Expand Down Expand Up @@ -64,7 +65,13 @@ extern "system" fn message_watcher_proc(
if w_param == 1
/*Ctrl + Shift + V*/
{
//TODO: Return to previous state (GetAsyncKeyState)
fn old_state(v_key: i32) -> u32 {
match is_key_pressed(v_key) {
Ok(false) => winuser::KEYEVENTF_KEYUP,
_ => 0,
}
}

match trigger_keys(
&[
winuser::VK_SHIFT as u16,
Expand All @@ -78,9 +85,9 @@ extern "system" fn message_watcher_proc(
winuser::KEYEVENTF_KEYUP,
winuser::KEYEVENTF_KEYUP,
winuser::KEYEVENTF_KEYUP,
0,
0,
0,
old_state(winuser::VK_CONTROL),
old_state('V' as i32),
old_state(winuser::VK_SHIFT),
],
) {
Ok(_) => {
Expand Down Expand Up @@ -167,7 +174,7 @@ pub fn run(opts: Opts) {
.unwrap();

let mut lp_msg = winuser::MSG::default();
println!("Ready");
// println!("Ready");
unsafe {
while winuser::GetMessageA(&mut lp_msg, ptr::null_mut(), 0, 0) != 0 {
winuser::TranslateMessage(&lp_msg);
Expand Down

0 comments on commit 32d2225

Please sign in to comment.