From d5369288fb61011f2892d135b12f90f2a6144ec0 Mon Sep 17 00:00:00 2001 From: Marty Gentillon Date: Wed, 28 Feb 2018 22:48:20 -0800 Subject: [PATCH] NumPad now restores the former num lock state on deactivation. --- src/Kaleidoscope-NumPad.cpp | 9 +++++++++ src/Kaleidoscope-NumPad.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/Kaleidoscope-NumPad.cpp b/src/Kaleidoscope-NumPad.cpp index ca7794aa..2e446a40 100644 --- a/src/Kaleidoscope-NumPad.cpp +++ b/src/Kaleidoscope-NumPad.cpp @@ -6,10 +6,12 @@ byte NumPad_::row = 255, NumPad_::col = 255; uint8_t NumPad_::numPadLayer; bool NumPad_::cleanupDone = true; +bool NumPad_::originalNumLockState = false; cRGB numpad_color = CRGB(255, 0, 0); void NumPad_::begin(void) { Kaleidoscope.useLoopHook(loopHook); + originalNumLockState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK); } void NumPad_::loopHook(bool postClear) { @@ -17,10 +19,17 @@ void NumPad_::loopHook(bool postClear) { return; if (!Layer.isOn(numPadLayer)) { + bool numState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK); if (!cleanupDone) { LEDControl.set_mode(LEDControl.get_mode_index()); cleanupDone = true; + + if (numState && !originalNumLockState) { + kaleidoscope::hid::pressKey(Key_KeypadNumLock); + numState = false; + } } + originalNumLockState = numState; return; } diff --git a/src/Kaleidoscope-NumPad.h b/src/Kaleidoscope-NumPad.h index 3d60b417..1f3c9010 100644 --- a/src/Kaleidoscope-NumPad.h +++ b/src/Kaleidoscope-NumPad.h @@ -17,6 +17,7 @@ class NumPad_ : public KaleidoscopePlugin { static byte row, col; static bool cleanupDone; + static bool originalNumLockState; }; extern NumPad_ NumPad;