Skip to content

Commit

Permalink
Special handling of right shift in windows hook
Browse files Browse the repository at this point in the history
  • Loading branch information
houmaster committed Apr 15, 2019
1 parent cdf2619 commit bf54010
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Build status](https://ci.appveyor.com/api/projects/status/ykij7d5lrw7yc52d?svg=true)](https://ci.appveyor.com/project/houmaster/keymapper)

keymapper
=========
Expand Down
3 changes: 1 addition & 2 deletions src/config/Key.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ enum class Key : KeyCode {
Comma = 0x0033,
Period = 0x0034,
Slash = 0x0035,
ShiftRight = 0x0036,
NumpadMultiply = 0x0037,
AltLeft = 0x0038,
Space = 0x0039,
Expand Down Expand Up @@ -93,7 +94,6 @@ enum class Key : KeyCode {
F12 = 0x0058,

#if defined(__linux__)
ShiftRight = 0x0036,
NumLock = 0x0045,
IntlRo = 0x0059,
Convert = 0x005C,
Expand Down Expand Up @@ -202,7 +202,6 @@ enum class Key : KeyCode {
AudioVolumeUp = 0xE030,
//BrowserHome = 0xE032,
NumpadDivide = 0xE035,
ShiftRight = 0xE036,
PrintScreen = 0xE037,
AltRight = 0xE038,
NumLock = 0xE045,
Expand Down
34 changes: 25 additions & 9 deletions src/win32/run_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,35 @@ namespace {
bool g_sending_key;
std::vector<INPUT> g_send_buffer;

KeyEvent get_key_event(WPARAM wparam, const KBDLLHOOKSTRUCT& kbd) {
auto key = static_cast<KeyCode>(kbd.scanCode |
(kbd.flags & LLKHF_EXTENDED ? 0xE000 : 0));

// special handling
if (key == 0xE036)
key = *Key::ShiftRight;

auto state = (wparam == WM_KEYDOWN || wparam == WM_SYSKEYDOWN ?
KeyState::Down : KeyState::Up);
return { key, state };
}

void send_event(const KeyEvent& event) {
auto key = INPUT{ };
key.type = INPUT_KEYBOARD;
key.ki.dwExtraInfo = injected_ident;
key.ki.dwFlags |= (event.state == KeyState::Up ? KEYEVENTF_KEYUP : 0);
key.ki.dwFlags |= KEYEVENTF_SCANCODE;
if (event.key & 0xE000)
key.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
key.ki.wScan = static_cast<WORD>(event.key);

// special handling
if (event.key == *Key::ShiftRight) {
key.ki.wVk = VK_RSHIFT;
}
else {
key.ki.dwFlags |= KEYEVENTF_SCANCODE;
if (event.key & 0xE000)
key.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
key.ki.wScan = static_cast<WORD>(event.key);
}
g_send_buffer.push_back(key);
}

Expand Down Expand Up @@ -59,11 +79,7 @@ namespace {
if (injected || g_sending_key)
return false;

const auto key = static_cast<KeyCode>(kbd.scanCode |
(kbd.flags & LLKHF_EXTENDED ? 0xE000 : 0));
const auto state = (wparam == WM_KEYDOWN || wparam == WM_SYSKEYDOWN ?
KeyState::Down : KeyState::Up);
const auto input = KeyEvent{ key, state };
const auto input = get_key_event(wparam, kbd);

auto translated = false;
auto output = apply_input(input);
Expand Down

0 comments on commit bf54010

Please sign in to comment.