Skip to content

Commit baaffbc

Browse files
committed
fix: rshift do not reverse while switching app
1 parent 48679bf commit baaffbc

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/config.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ impl Hotkey {
216216
return None;
217217
}
218218
let modifier = match keys[0] {
219-
"win" => [0xe05b, 0xe05c],
220-
"alt" => [0x38, 0xe038],
221-
"ctrl" => [0x1d, 0xe01d],
219+
"win" => [0x5b, 0x5c],
220+
"alt" => [0x38, 0x38],
221+
"ctrl" => [0x1d, 0x1d],
222222
_ => {
223223
return None;
224224
}
@@ -254,17 +254,17 @@ impl Hotkey {
254254
"oem_102" => 0x56,
255255
"f11" => 0x57,
256256
"f12" => 0x58,
257-
"home" => 0xe047,
258-
"up" => 0xe048,
259-
"pageup" => 0xe049,
260-
"left" => 0xe04b,
261-
"right" => 0xe04d,
262-
"end" => 0xe04f,
263-
"down" => 0xe050,
264-
"pagedown" => 0xe051,
265-
"insert" => 0xe052,
266-
"delete" => 0xe053,
267-
"menu" => 0xe05d,
257+
"home" => 0x47,
258+
"up" => 0x48,
259+
"pageup" => 0x49,
260+
"left" => 0x4b,
261+
"right" => 0x4d,
262+
"end" => 0x4f,
263+
"down" => 0x50,
264+
"pagedown" => 0x51,
265+
"insert" => 0x52,
266+
"delete" => 0x53,
267+
"menu" => 0x5d,
268268
_ => return None,
269269
};
270270
Some((modifier, code))
@@ -324,7 +324,7 @@ mod tests {
324324

325325
#[test]
326326
fn test_hotkey() {
327-
assert_eq!(Hotkey::parse("alt + `"), Some(([0x38, 0xe038], 0x29)));
328-
assert_eq!(Hotkey::parse("alt + tab"), Some(([0x38, 0xe038], 0x0f)));
327+
assert_eq!(Hotkey::parse("alt + `"), Some(([0x38, 0x38], 0x29)));
328+
assert_eq!(Hotkey::parse("alt + tab"), Some(([0x38, 0x38], 0x0f)));
329329
}
330330
}

src/keyboard.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use windows::Win32::{
1717
Input::KeyboardAndMouse::{SCANCODE_LSHIFT, SCANCODE_RSHIFT},
1818
WindowsAndMessaging::{
1919
CallNextHookEx, SendMessageW, SetWindowsHookExW, UnhookWindowsHookEx, HHOOK,
20-
KBDLLHOOKSTRUCT, WH_KEYBOARD_LL,
20+
KBDLLHOOKSTRUCT, LLKHF_UP, WH_KEYBOARD_LL,
2121
},
2222
},
2323
};
@@ -76,12 +76,8 @@ unsafe extern "system" fn keyboard_proc(code: i32, w_param: WPARAM, l_param: LPA
7676
let kbd_data: &KBDLLHOOKSTRUCT = &*(l_param.0 as *const _);
7777
debug!("keyboard {kbd_data:?}");
7878
let mut is_modifier = false;
79-
let scan_code = if kbd_data.flags.0 & 1 == 0 {
80-
kbd_data.scanCode
81-
} else {
82-
kbd_data.scanCode | 0xe000
83-
};
84-
let is_key_pressed = || kbd_data.flags.0 & 128 == 0;
79+
let scan_code = kbd_data.scanCode;
80+
let is_key_pressed = || kbd_data.flags.0 & LLKHF_UP.0 == 0;
8581
if [SCANCODE_LSHIFT, SCANCODE_RSHIFT].contains(&scan_code) {
8682
IS_SHIFT_PRESSED = is_key_pressed();
8783
}

0 commit comments

Comments
 (0)