General2026-07-21

My Keyboard\x27s Secret Codes — Finding Key Codes You Never Knew Existed

I pressed a key on my keyboard and got a number back that unlocked a rabbit hole of hidden key codes. Some of them do not even have physical keys attached to them.

I was building a keyboard shortcut feature for a small web app I was working on. Just a simple little tool. Press a key, capture the keycode, map it to an action. I threw together a quick keydown event listener that logged the event.code and event.key to the console. Pressed the letter J. Got 74. Pressed Enter. Got 13. Normal stuff. Then, out of curiosity, I pressed the Pause key — that dusty key between Print Screen and Scroll Lock that I had never touched intentionally in my life. It returned 19. I pressed Scroll Lock. Another number I had never seen. Suddenly I was pressing every key on my keyboard, writing down numbers like I was decoding an ancient cipher. That was how I fell into the world of key codes, and it is way more interesting than I expected. The first thing I learned is that there is a difference between the physical key and the character it produces. event.key gives you the character — "a", "b", "1", "!" — based on what is actually typed. event.code gives you the physical key location on the keyboard, like "KeyA" or "Digit1", regardless of what modifier keys are pressed. Pressing Shift+1 gives you "!" for event.key but always "Digit1" for event.code. This distinction matters way more than I realized. If you are building keyboard shortcuts, you almost always want event.code, because it does not matter what language layout the user has. A German keyboard has different letter positions than a US one, but the physical location of the key stays the same. Then I discovered the keys that do not even exist on most keyboards. There is a keycode for "Close" — an X button some keyboards have. There is a keycode for "Mail" that opens the default email client. "Calculator" launches the calculator app. "Sleep" puts the computer to sleep. These are media and special function keys that many keyboards include but most developers never handle. The function keys past F12 were a revelation. F13 through F24 exist. I have never seen a keyboard with F13 on it, but the keycodes are there. They exist for legacy compatibility with old terminal keyboards that had physical F13 through F24 keys. The codes are still in the specification. Then there are the modifier key combinations. Holding Ctrl, Alt, and Shift simultaneously and pressing a letter gives you a completely different keycode path than pressing the letter alone. The browser's event object distinguishes between left and right modifiers too — event.ctrlKey versus just checking if control is held. The left Shift and right Shift are different physical keys and you can check them separately. I built a little tool that displays every keycode live as I type. It is sitting in a bookmark on my browser bar now. Whenever I need to map a new shortcut, I just open it and press the key combination I want and copy the code. No more guessing whether it is "Comma" or "«" or 188. Honestly, the most fun part was just pressing random keys and watching numbers appear. The Pause key still makes me smile every time I hit it.