Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #7 from MartyGentillon/master
Browse files Browse the repository at this point in the history
Numpad now properly restores the former numlock state on deactivation.
  • Loading branch information
obra authored Aug 11, 2018
2 parents 120d2d7 + effa6eb commit 386787f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Kaleidoscope-NumPad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,28 @@ kaleidoscope::EventHandlerResult NumPad_::onSetup(void) {
return kaleidoscope::EventHandlerResult::OK;
}

static bool getNumlockState() {
return !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK);
}

static void syncNumlock(bool state) {
bool numState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK);
bool numState = getNumlockState();
if (numState != state) {
kaleidoscope::hid::pressKey(Key_KeypadNumLock);
}
}

kaleidoscope::EventHandlerResult NumPad_::afterEachCycle() {
if (!Layer.isOn(numPadLayer)) {
bool numState = !!(kaleidoscope::hid::getKeyboardLEDs() & LED_NUM_LOCK);
bool numState = getNumlockState();
if (!cleanupDone) {
LEDControl.set_mode(LEDControl.get_mode_index());
syncNumlock(false);
cleanupDone = true;

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

Expand Down

0 comments on commit 386787f

Please sign in to comment.