Skip to content

Commit

Permalink
directvt#400 WIP: Suppress spam from pressed keyboard modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Sep 15, 2023
1 parent f2322d6 commit 98b44f5
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/netxs/desktopio/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,32 @@ namespace netxs::os
modstate = state;
return changed;
}
template<class T1, class T2 = si32>
auto modstat(si32& modstate, T1 ms_ctrls, T2 scancode, bool pressed)
{
struct
{
bool changed{}; // Modifiers state changed.
bool repeats{}; // Modifier repeated.
} stat;
stat.changed = kbstate(modstate, ms_ctrls, scancode, pressed);
if (!pressed) return stat;
if (stat.changed) return stat;
scancode |= ms_ctrls & ENHANCED_KEY;
stat.repeats = scancode == 0x002a // input::hids::LShift
|| scancode == 0x0036 // input::hids::RShift (Windows command prompt)
|| scancode == 0x0136 // input::hids::RShift (Windows terminal)
|| scancode == 0x005b // input::hids::LWin
|| scancode == 0x005c // input::hids::RWin
|| scancode == 0x001d // input::hids::LCtrl
|| scancode == 0x011d // input::hids::RCtrl
|| scancode == 0x0038 // input::hids::LAlt
|| scancode == 0x0138 // input::hids::RAlt
|| scancode == 0x0145 // input::hids::NumLock
|| scancode == 0x003a // input::hids::CapsLock
|| scancode == 0x0046; // input::hids::ScrlLock
return stat;
}
auto ms_kbstate()
{
auto vkeys = std::array<BYTE, 256>{};
Expand Down Expand Up @@ -4050,7 +4076,10 @@ namespace netxs::os
switch (r.EventType)
{
case KEY_EVENT:
if (os::nt::kbstate(kbmod, r.Event.KeyEvent.dwControlKeyState, r.Event.KeyEvent.wVirtualScanCode, r.Event.KeyEvent.bKeyDown))
{
auto modstat = os::nt::modstat(kbmod, r.Event.KeyEvent.dwControlKeyState, r.Event.KeyEvent.wVirtualScanCode, r.Event.KeyEvent.bKeyDown);
if (modstat.repeats) break; // We don't repeat modifiers.
else if (modstat.changed)
{
k.ctlstat = kbmod;
m.ctlstat = kbmod;
Expand Down Expand Up @@ -4107,6 +4136,7 @@ namespace netxs::os
point = {};
toutf.clear();
break;
}
case MENU_EVENT: // Forward console control events.
if (r.Event.MenuEvent.dwCommandId & nt::console::event::custom)
switch (r.Event.MenuEvent.dwCommandId ^ nt::console::event::custom)
Expand Down

0 comments on commit 98b44f5

Please sign in to comment.