Skip to content

Commit bf54010

Browse files
author
houmaster
committed
Special handling of right shift in windows hook
1 parent cdf2619 commit bf54010

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[![Build status](https://ci.appveyor.com/api/projects/status/ykij7d5lrw7yc52d?svg=true)](https://ci.appveyor.com/project/houmaster/keymapper)
12

23
keymapper
34
=========

src/config/Key.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ enum class Key : KeyCode {
6060
Comma = 0x0033,
6161
Period = 0x0034,
6262
Slash = 0x0035,
63+
ShiftRight = 0x0036,
6364
NumpadMultiply = 0x0037,
6465
AltLeft = 0x0038,
6566
Space = 0x0039,
@@ -93,7 +94,6 @@ enum class Key : KeyCode {
9394
F12 = 0x0058,
9495

9596
#if defined(__linux__)
96-
ShiftRight = 0x0036,
9797
NumLock = 0x0045,
9898
IntlRo = 0x0059,
9999
Convert = 0x005C,
@@ -202,7 +202,6 @@ enum class Key : KeyCode {
202202
AudioVolumeUp = 0xE030,
203203
//BrowserHome = 0xE032,
204204
NumpadDivide = 0xE035,
205-
ShiftRight = 0xE036,
206205
PrintScreen = 0xE037,
207206
AltRight = 0xE038,
208207
NumLock = 0xE045,

src/win32/run_hook.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,35 @@ namespace {
1212
bool g_sending_key;
1313
std::vector<INPUT> g_send_buffer;
1414

15+
KeyEvent get_key_event(WPARAM wparam, const KBDLLHOOKSTRUCT& kbd) {
16+
auto key = static_cast<KeyCode>(kbd.scanCode |
17+
(kbd.flags & LLKHF_EXTENDED ? 0xE000 : 0));
18+
19+
// special handling
20+
if (key == 0xE036)
21+
key = *Key::ShiftRight;
22+
23+
auto state = (wparam == WM_KEYDOWN || wparam == WM_SYSKEYDOWN ?
24+
KeyState::Down : KeyState::Up);
25+
return { key, state };
26+
}
27+
1528
void send_event(const KeyEvent& event) {
1629
auto key = INPUT{ };
1730
key.type = INPUT_KEYBOARD;
1831
key.ki.dwExtraInfo = injected_ident;
1932
key.ki.dwFlags |= (event.state == KeyState::Up ? KEYEVENTF_KEYUP : 0);
20-
key.ki.dwFlags |= KEYEVENTF_SCANCODE;
21-
if (event.key & 0xE000)
22-
key.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
23-
key.ki.wScan = static_cast<WORD>(event.key);
33+
34+
// special handling
35+
if (event.key == *Key::ShiftRight) {
36+
key.ki.wVk = VK_RSHIFT;
37+
}
38+
else {
39+
key.ki.dwFlags |= KEYEVENTF_SCANCODE;
40+
if (event.key & 0xE000)
41+
key.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
42+
key.ki.wScan = static_cast<WORD>(event.key);
43+
}
2444
g_send_buffer.push_back(key);
2545
}
2646

@@ -59,11 +79,7 @@ namespace {
5979
if (injected || g_sending_key)
6080
return false;
6181

62-
const auto key = static_cast<KeyCode>(kbd.scanCode |
63-
(kbd.flags & LLKHF_EXTENDED ? 0xE000 : 0));
64-
const auto state = (wparam == WM_KEYDOWN || wparam == WM_SYSKEYDOWN ?
65-
KeyState::Down : KeyState::Up);
66-
const auto input = KeyEvent{ key, state };
82+
const auto input = get_key_event(wparam, kbd);
6783

6884
auto translated = false;
6985
auto output = apply_input(input);

0 commit comments

Comments
 (0)