Skip to content

Commit

Permalink
Merge pull request keyboardio#3 from MartyGentillon/master
Browse files Browse the repository at this point in the history
NumPad now restores the former num lock state on deactivation.
  • Loading branch information
algernon authored Mar 9, 2018
2 parents 3e7b4cb + d536928 commit 78710d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Kaleidoscope-NumPad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

static void syncNumlock(bool state) {
Expand All @@ -24,11 +26,18 @@ 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());
syncNumlock(false);
cleanupDone = true;

if (numState && !originalNumLockState) {
kaleidoscope::hid::pressKey(Key_KeypadNumLock);
numState = false;
}
}
originalNumLockState = numState;
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/Kaleidoscope-NumPad.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class NumPad_ : public KaleidoscopePlugin {

static byte row, col;
static bool cleanupDone;
static bool originalNumLockState;
};

extern NumPad_ NumPad;

0 comments on commit 78710d0

Please sign in to comment.