# On the history and implementation of NumLock

**URL:** https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735
**Category:** Kaleidoscope Internals
**Created:** [November 9, 2017, 6:42pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735 "2017-11-09T18:42:49Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![andrewg](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/andrewg/32/43_2.png) [@andrewg](https://community.keyboard.io/u/andrewg)
#### Post date: [November 9, 2017, 6:42pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/1 "2017-11-09T18:42:49Z")

</div>

So, I feel it’s time for another mild rant about leaky abstractions. 🙂

NumLock is a kludge. It is a kludge designed for the first IBM PC so that a directional pad and a numpad could be supported on the same limited keyboard. Its inadequacy was soon evident, so the PC/AT model M and all subsequent IBM compatible PCs have supported keyboards with separate directional and numeric keys.

To its eternal credit, Apple never implemented NumLock. To its eternal shame, Linux did.

Unfortunately, because NumLock was a _software_ feature it had to be kept around for backwards compatibility. And then it became unkillable, to the point where modern compact keyboards that have no hard numpad (laptops, kinesis, Model01…) still have to handle NumLock.

The vast majority of PC-compatible hardware has long supported a _default_ BIOS option “Enable NumLock on boot”, which effectively means that the user can pretend that NumLock does not exist. This appears to me to be the sensible option, and is one that is both widely supported and widely _expected_. On most laptop keyboards the numpad is accessed by holding down Fn. With NumLock-on-boot, this produces numbers, as it should. NumLock itself is normally hidden so well that it takes a magnifying glass to find it (on my Dell, it is Fn-F5). The only problem comes if you disable it by accident (which is why it is well hidden).

For whatever reason, the Model01 does things differently. Instead of letting the BIOS enable NumLock-on-boot and follow the practice of every other compact keyboard, it overloads the Num key and makes it toggle both the software NumLock and the firmware keypad options. When these remain in sync, nobody notices. When these fall out of sync, we have a nasty abstraction leak that renders the numpad unusable.

What is the advantage in a “smart” numlock key like this? What problem does it solve?

---

<div class="post-metadata">

### Author: ![rick](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/rick/32/544_2.png) [@rick](https://community.keyboard.io/u/rick)
#### Post date: [November 9, 2017, 6:57pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/2 "2017-11-09T18:57:10Z")

</div>

> [@andrewg](#):
>
> When these remain in sync, nobody notices. When these fall out of sync, we have a nasty abstraction leak that renders the numpad unusable.

hehe, nasty! thanks for the heads up…

---

<div class="post-metadata">

### Author: ![james.nvc](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/james.nvc/32/54_2.png) [@james.nvc](https://community.keyboard.io/u/james.nvc)
#### Post date: [November 9, 2017, 7:00pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/3 "2017-11-09T19:00:26Z")

</div>

Yeah…I ended up just replacing all the Key\_Numpad\* keys with Key\_Num\* because it seemed more straightforward - I was getting arrow keys instead of numbers, for this reason, I suppose.

---

<div class="post-metadata">

### Author: ![jesse](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/jesse/32/361_2.png) [@jesse](https://community.keyboard.io/u/jesse)
#### Post date: [November 9, 2017, 7:27pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/4 "2017-11-09T19:27:53Z")

</div>

> [@andrewg](#):
>
> For whatever reason, the Model01 does things differently. Instead of letting the BIOS enable NumLock-on-boot and follow the practice of every other compact keyboard, it overloads the Num key and makes it toggle both the software NumLock and the firmware keypad options. When these remain in sync, nobody notices. When these fall out of sync, we have a nasty abstraction leak that renders the numpad unusable.
> 
> What is the advantage in a “smart” numlock key like this? What problem does it solve?

Nothing. This was a naive implementation on my part that should now be fixed in the source repo.

---

<div class="post-metadata">

### Author: ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)
#### Post date: [November 9, 2017, 7:35pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/5 "2017-11-09T19:35:58Z")

</div>

I was planning to just ignore `NumLock` altogether in my sketch. I can’t think of anything I actually need `Key_Numpad*` for. Does it really provide any utility at all?

---

<div class="post-metadata">

### Author: ![ejinks4](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@ejinks4](https://community.keyboard.io/u/ejinks4)
#### Post date: [November 9, 2017, 7:38pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/6 "2017-11-09T19:38:12Z")

</div>

Just out of curiosity, what will the new behavior be? Just a firmware toggle? If so will the Model 01 numpad functionality change if the PC is (or isn’t) in NumLock?

Thanks again for your responsiveness on all these little issues. I sometimes feel like we are pretty demanding crowd, but you handle everything and everyone with such grace!

---

<div class="post-metadata">

### Author: ![ejinks4](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@ejinks4](https://community.keyboard.io/u/ejinks4)
#### Post date: [November 9, 2017, 7:41pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/7 "2017-11-09T19:41:33Z")

</div>

I do a good amount of number entry (spreadsheets and accounting and all that fun stuff). Not having a number pad makes some tasks a lot slower. I’m appreciative of the effort to include that functionality in the keyboard, but I may end up with a standalone number pad unit, personally.

---

<div class="post-metadata">

### Author: ![jesse](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/jesse/32/361_2.png) [@jesse](https://community.keyboard.io/u/jesse)
#### Post date: [November 9, 2017, 7:48pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/8 "2017-11-09T19:48:02Z")

</div>

The thing that @algernon put together most recently is for us to be aware of and honor the PC’s numlock state. I need to play with the design a little bit to decide how we’re going to expose Numlock vs the numpad layer toggle.

---

<div class="post-metadata">

### Author: ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)
#### Post date: [November 9, 2017, 9:05pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/9 "2017-11-09T21:05:41Z")

</div>

> [@ejinks4](#):
>
> I do a good amount of number entry (spreadsheets and accounting and all that fun stuff). Not having a number pad makes some tasks a lot slower.

The thing is, with a programmable keyboard, you can have a number pad without needing the keycodes for the number pad. I’m contemplating having a layout where the numbers are only available on a “numpad” layer, but those numbers are `Key_8` (for example), not `Key_Keypad8`. I’m not aware of any need for the latter, and the former are unaffected by the host’s NumLock state.

---

<div class="post-metadata">

### Author: ![ejinks4](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@ejinks4](https://community.keyboard.io/u/ejinks4)
#### Post date: [November 9, 2017, 9:08pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/10 "2017-11-09T21:08:00Z")

</div>

> [@merlin](#):
>
> The thing is, with a programmable keyboard, you can have a number pad without needing the keycodes for the number pad. I’m contemplating having a layout where the numbers are only available on a “numpad” layer, but those numbers are `Key_8` (for example), not `Key_Keypad8`. I’m not aware of any need for the latter, and the former are unaffected by the host’s NumLock state.

I get what you’re saying now. In other words, what’s the point of sending the keypad codes vs. just the regular number codes on the numpad layer. Agreed - probably not much point.

---

<div class="post-metadata">

### Author: ![andrewg](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/andrewg/32/43_2.png) [@andrewg](https://community.keyboard.io/u/andrewg)
#### Post date: [November 9, 2017, 9:15pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/11 "2017-11-09T21:15:26Z")

</div>

> [@merlin](#):
>
> I’m contemplating having a layout where the numbers are only available on a “numpad” layer, but those numbers are Key\_8 (for example), not Key\_Keypad8. I’m not aware of any need for the latter, and the former are unaffected by the host’s NumLock state.

They aren’t affected by NumLock, but they are affected by OS keymap. For example, azerty uses them for accented letters and punctuation. Programmer-Dvorak uses them for brackets and symbols. And Hungarian zero is not where you think it is.

---

<div class="post-metadata">

### Author: ![Jennigma](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/jennigma/32/353_2.png) [@Jennigma](https://community.keyboard.io/u/Jennigma)
#### Post date: [November 9, 2017, 9:39pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/12 "2017-11-09T21:39:10Z")

</div>

I’m trying to document the way keymaps work, and thinking about how to explain the magic `Key_KeypadNumLock`. It would make a lot more sense if it were `LockLayer(NUMPAD)`. I had forgotten that it wasn’t defined that way.

---

<div class="post-metadata">

### Author: ![jesse](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/jesse/32/361_2.png) [@jesse](https://community.keyboard.io/u/jesse)
#### Post date: [November 9, 2017, 9:54pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/13 "2017-11-09T21:54:05Z")

</div>

> [@Jennigma](#):
>
> I’m trying to document the way keymaps work, and thinking about how to explain the magic Key\_KeypadNumLock. It would make a lot more sense if it were LockLayer(NUMPAD). I had forgotten that it wasn’t defined that way.

It…may be that way again in the not too distant future.

---

<div class="post-metadata">

### Author: ![Jennigma](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/jennigma/32/353_2.png) [@Jennigma](https://community.keyboard.io/u/Jennigma)
#### Post date: [November 9, 2017, 10:12pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/14 "2017-11-09T22:12:46Z")

</div>

🙂 If you change it poke me to revise the docs. 🙂

As a side note, I’m adding the things that are called out in the default .ino as needing documentation to the wiki intro, so a lot of that comment block could be replaced with a link. I don’t know when you are pushing a revision to Arduino, but please let’s get that revised before it goes live.

---

<div class="post-metadata">

### Author: ![buc](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/buc/32/523_2.png) [@buc](https://community.keyboard.io/u/buc)
#### Post date: [November 9, 2017, 10:16pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/15 "2017-11-09T22:16:39Z")

</div>

> [@merlin](#):
>
> I can’t think of anything I actually need Key\_Numpad\* for. Does it really provide any utility at all?

This definitely isn’t the most serious of needs, but in heavily modded Minecraft one can quickly run out of mappable keys. The fact that the keypad keycodes are distinct from the keycodes for the “regular” numbers is taken for granted in the default key mappings used by some of the mods.

For those not familiar with Minecraft, you have a hotbar with nine slots, with the “regular” numbers 1-9 switching your active item to the one in that slot.

Because Key\_Numpad0 is distinct from Key\_0 it can be assigned something different. (disclaimer, I’m fairly certain that those aren’t the correct keycode names).

I’m undecided whether this is an argument in favor of things NumLock or an example of just how badly misused the feature has become. Maybe both.

I think this means that we probably ought to keep these Key\_Numpad\* codes mapped in the default firmware.

This is something I still haven’t figured out how I’m going to address when I build my own layout.

---

<div class="post-metadata">

### Author: ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)
#### Post date: [November 9, 2017, 11:17pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/16 "2017-11-09T23:17:46Z")

</div>

> [@andrewg](#):
>
> They aren’t affected by NumLock, but they are affected by OS keymap. For example, azerty uses them for accented letters and punctuation. Programmer-Dvorak uses them for brackets and symbols. And Hungarian zero is not where you think it is.

All true, but irrelevant to the question of whether the keycodes for the keys on the numeric keypad are actually useful for anything.

---

<div class="post-metadata">

### Author: ![merlin](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/merlin/32/3416_2.png) [@merlin](https://community.keyboard.io/u/merlin)
#### Post date: [November 9, 2017, 11:19pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/17 "2017-11-09T23:19:05Z")

</div>

> [@buc](#):
>
> This definitely isn’t the most serious of needs, but in heavily modded Minecraft one can quickly run out of mappable keys.

This was the kind of thing I was guessing. Can’t you assign those functions to letter keys, though?

---

<div class="post-metadata">

### Author: ![andrewg](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/andrewg/32/43_2.png) [@andrewg](https://community.keyboard.io/u/andrewg)
#### Post date: [November 9, 2017, 11:27pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/18 "2017-11-09T23:27:12Z")

</div>

Under Windows, alt+numpad gives you arbitrary Unicode codepoints. Alt+number row does not.

---

<div class="post-metadata">

### Author: ![andrewg](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/andrewg/32/43_2.png) [@andrewg](https://community.keyboard.io/u/andrewg)
#### Post date: [November 9, 2017, 11:30pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/19 "2017-11-09T23:30:09Z")

</div>

> [@merlin](#):
>
> All true, but irrelevant to the question of whether the keycodes for the keys on the numeric keypad are actually useful for anything.

They are useful when you want to type a number in a way that is keymap independent. If you were to assign number row scancodes to the keypad numbers, it would only work the way you expect some of the time.

---

<div class="post-metadata">

### Author: ![jesse](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.keyboard.io/jesse/32/361_2.png) [@jesse](https://community.keyboard.io/u/jesse)
#### Post date: [November 9, 2017, 11:46pm UTC](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735/20 "2017-11-09T23:46:07Z")

</div>

They’re also useful if you want to end up with the _non_ Numlock variants of those keys.

Mostly, we wanted to use those keys because there are random odd things that depend on the exact HID key events for numpad keys and we’d be happier not to break things.

If we hadn’t sorted out the system numlock toggle problem, my plan was to use the non-numpad versions of the keys as a stopgap.

[Next page](https://community.keyboard.io/t/on-the-history-and-implementation-of-numlock/735.md?page=2)
