diff --git a/src/Kaleidoscope-Numlock.cpp b/src/Kaleidoscope-Numlock.cpp index c0d31150..5bd2dc33 100644 --- a/src/Kaleidoscope-Numlock.cpp +++ b/src/Kaleidoscope-Numlock.cpp @@ -5,15 +5,29 @@ byte NumLock_::row = 255, NumLock_::col = 255; uint8_t NumLock_::numPadLayer; +bool NumLock_::isOn; cRGB numpad_color = CRGB(255, 0, 0); void NumLock_::begin(void) { Kaleidoscope.useLoopHook(loopHook); - Kaleidoscope.useEventHandlerHook(eventHandlerHook); } void NumLock_::loopHook(bool postClear) { - if (!postClear || !Layer.isOn(numPadLayer)) + if (!postClear) + return; + + bool numState = !!(Keyboard.getLEDs() & LED_NUM_LOCK); + if (numState != isOn) { + isOn = numState; + if (isOn) { + Layer.on(numPadLayer); + } else { + Layer.off(numPadLayer); + LEDControl.set_mode(LEDControl.get_mode_index()); + } + } + + if (!isOn) return; for (uint8_t r = 0; r < ROWS; r++) { @@ -36,21 +50,4 @@ void NumLock_::loopHook(bool postClear) { LEDControl.setCrgbAt(row, col, color); } -Key NumLock_::eventHandlerHook(Key key, byte row, byte col, uint8_t key_state) { - if (key != Key_KeypadNumLock) - return key; - - if (!keyToggledOn(key_state)) - return key; - - if (Layer.isOn(numPadLayer)) { - Layer.off(numPadLayer); - LEDControl.set_mode(LEDControl.get_mode_index()); - } else { - Layer.on(numPadLayer); - } - - return key; -} - NumLock_ NumLock; diff --git a/src/Kaleidoscope-Numlock.h b/src/Kaleidoscope-Numlock.h index d9d42871..9b147d4d 100644 --- a/src/Kaleidoscope-Numlock.h +++ b/src/Kaleidoscope-Numlock.h @@ -14,9 +14,9 @@ class NumLock_ : public KaleidoscopePlugin { private: static void loopHook(const bool postClear); - static Key eventHandlerHook(Key key, byte row, byte col, uint8_t key_state); static byte row, col; + static bool isOn; }; extern NumLock_ NumLock;