r/olkb • u/scoobywan • Jan 09 '17
Solved QMK Num Lock
I have created a layer that includes the numpad keys, but can't figure out how to force the "num lock" to an ON state. At first I thought just simulating the NumLock press when the layer was activated, but that wasn't very predictable. So is there a way to check for NumLock and turn it ON if it's currently OFF?
** MY SOLUTION **
Thanks for the help everybody
I found a way to make it work with the actual numlock keys, and take care of toggling numlock if it isn't on.
first I added 2 bool variables:
bool bnumlock = false;
bool numlock_changed = false;then I added code for the led_set_kb event:
void led_set_kb(uint8_t usb_led) {
if (usb_led & (1<<USB_LED_NUM_LOCK)) {
bnumlock = true;
} else {
bnumlock = false;
}
}and finally I added the code to the macro switch statement:
case 3:
if (record->event.pressed) {
if(!bnumlock) {
numlock_changed = true;
register_code(KC_NLCK);
unregister_code(KC_NLCK);
}
layer_on(3);
} else {
if(bnumlock && numlock_changed) {
numlock_changed = false;
register_code(KC_NLCK);
unregister_code(KC_NLCK);
}
layer_off(3);
}
1
u/Danilo_dk Jan 09 '17
For what reason do you need the numlock to be on? In what way does it change the behavior of that layer? Perhaps there is another way to fix your problem without having to mess with numlock.
1
u/ylaway Jan 10 '17 edited Jan 10 '17
You could create a layer for numbers and then use the Toggle layer [code]. I presume you are trying to set the number lock up on a separate layer. The toggle action could be embedded in that layer with the default being off so the Pg up/down keys are present and when the toggle is switched on and it would keep the number lock turned on. It would have mean that the number layer is held until you switch it off though. I have not implemented this myself.
See documentation :
You could just use a held function key to achieve this (chorded style) which is how I chose to implement](http://imgur.com/D3m1CwI)
2
u/InkyandtheCerebellum Jan 09 '17
Is there still a bios setting the defaults the num lock to on? There used to be.
1
u/phaeew Jan 09 '17 edited Jan 09 '17
I think you are pretty limited...
You can simulate the "numpad on" by using normal number keys. Then make a layer with the arrows and home and end with the "numlock off" version of the keypad.
It looks like most people use AutoHotKey to just make sure the numlock stays on all the time if they need to use keypad numbers.
More info on it here:
https://geekhack.org/index.php?topic=36222.0