diff --git a/src/Kaleidoscope-Numlock.cpp b/src/Kaleidoscope-Numlock.cpp index 651975da..c7f2adf1 100644 --- a/src/Kaleidoscope-Numlock.cpp +++ b/src/Kaleidoscope-Numlock.cpp @@ -5,7 +5,7 @@ byte NumLock_::row = 255, NumLock_::col = 255; uint8_t NumLock_::numPadLayer; -bool NumLock_::isOn; +bool NumLock_::cleanupDone = true; cRGB numpad_color = CRGB(255, 0, 0); void NumLock_::begin(void) { @@ -16,25 +16,33 @@ void NumLock_::loopHook(bool postClear) { if (!postClear) return; - bool numState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK); - if (numState != isOn) { - isOn = numState; - if (isOn) { - Layer.on(numPadLayer); - } else { - Layer.off(numPadLayer); + if (!Layer.isOn(numPadLayer)) { + if (!cleanupDone) { LEDControl.set_mode(LEDControl.get_mode_index()); + cleanupDone = true; } + return; } - if (!isOn) - return; + cleanupDone = false; + bool numState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK); + if (!numState) { + kaleidoscope::hid::pressKey(Key_KeypadNumLock); + kaleidoscope::hid::sendKeyboardReport(); + } + + LEDControl.set_mode(LEDControl.get_mode_index()); for (uint8_t r = 0; r < ROWS; r++) { for (uint8_t c = 0; c < COLS; c++) { Key k = Layer.lookupOnActiveLayer(r, c); Key layer_key = Layer.getKey(numPadLayer, r, c); + if (k == LockLayer(numPadLayer)) { + row = r; + col = c; + } + if ((k != layer_key) || (k.flags != KEY_FLAGS)) { LEDControl.refreshAt(r, c); } else { diff --git a/src/Kaleidoscope-Numlock.h b/src/Kaleidoscope-Numlock.h index 9b147d4d..bf33aa5e 100644 --- a/src/Kaleidoscope-Numlock.h +++ b/src/Kaleidoscope-Numlock.h @@ -16,7 +16,7 @@ class NumLock_ : public KaleidoscopePlugin { static void loopHook(const bool postClear); static byte row, col; - static bool isOn; + static bool cleanupDone; }; extern NumLock_ NumLock;