Skip to content

Commit

Permalink
Improved Pause/NumLock key handling on Windows Pt.2
Browse files Browse the repository at this point in the history
  • Loading branch information
houmain committed Jul 21, 2022
1 parent 8d59442 commit a9b6273
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/server/windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,19 @@ namespace {
}
}

bool translate_input(const KeyEvent& input) {
bool translate_input(KeyEvent input) {
// ignore key repeat while a flush is pending
if (g_flush_scheduled && input == g_last_key_event)
return true;

// turn NumLock succeeding Pause into another Pause
auto translated_numlock_to_pause = false;
if (input.state == g_last_key_event.state &&
input.key == Key::NumLock &&
g_last_key_event.key == Key::Pause) {
input.key = Key::Pause;
translated_numlock_to_pause = true;
}
g_last_key_event = input;

// after OutputOnRelease block input until trigger is released
Expand All @@ -200,7 +209,8 @@ namespace {
const auto translated =
output.size() != 1 ||
output.front().key != input.key ||
(output.front().state == KeyState::Up) != (input.state == KeyState::Up);
(output.front().state == KeyState::Up) != (input.state == KeyState::Up) ||
translated_numlock_to_pause;

const auto intercept_and_send =
g_flush_scheduled ||
Expand All @@ -222,19 +232,13 @@ namespace {
if (!kbd.scanCode || injected || g_sending_key)
return false;

auto input = get_key_event(wparam, kbd);
const auto input = get_key_event(wparam, kbd);

// intercept ControlRight preceding AltGr
const auto ControlRightPrecedingAltGr = 0x21D;
if (*input.key == ControlRightPrecedingAltGr)
return true;

// turn NumLock succeeding Pause into another Pause
if (input.state == g_last_key_event.state &&
input.key == Key::NumLock &&
g_last_key_event.key == Key::Pause)
input.key = Key::Pause;

return translate_input(input);
}

Expand Down

0 comments on commit a9b6273

Please sign in to comment.