Overview
Introduction
Before KeyboardEvent.key existed, browsers reported keyboard input as a numeric keyCode identifying which physical key was pressed, and plenty of legacy JavaScript, browser-compatibility tables, and old Stack Overflow answers still reference these numbers.
This tool converts plain ASCII text into the keyCode sequence a US QWERTY keyboard would have historically reported for each character, useful for reading, testing, or documenting code that still relies on this deprecated property.
What Is ASCII to Keycodes Converter?
A lookup tool that maps each character in your input to its legacy JS KeyboardEvent.keyCode value on a standard US QWERTY layout.
It only covers characters with one clear, broadly documented keyCode: digits, letters, space, and 11 specific OEM punctuation keys, rejecting anything else rather than guessing at an ambiguous mapping.
How ASCII to Keycodes Converter Works
The input is validated as strict 7-bit ASCII, then each character is looked up in a fixed table built from the well-known keyCode ranges (48-57 for digits, 65-90 for letters) plus the documented OEM virtual-key codes for punctuation.
Letters are matched case-insensitively since keyCode itself carries no case information; any character outside the table (control characters, shifted symbols like "!" or ":") stops conversion with an error naming that character and its position.
When To Use ASCII to Keycodes Converter
Use it when reading or debugging legacy JavaScript that branches on event.keyCode, to quickly see what value a given character would have produced.
It's also useful for building test fixtures or documentation that need to reference historical keyCode values without digging through old compatibility tables by hand.
Often used alongside Keycodes to ASCII Converter, ASCII to Scan Codes Converter and ASCII to Hex Converter.
Features
Advantages
- Encodes an entire string at once instead of looking up keyCodes character by character.
- Sticks to only the well-documented, unambiguous portion of the keyCode table rather than presenting a guess as fact.
- Pairs directly with Keycodes to ASCII Converter for round-tripping.
Limitations
- Cannot represent shifted symbols ("!", "@", ":", etc.) or most control characters, since there's no single universally agreed keyCode for them; these are rejected outright.
- keyCode is a deprecated, non-standard property with layout- and browser-dependent quirks in the wild; this tool implements one commonly cited US-QWERTY reference table, not every browser's exact historical behavior.
Examples
Best Practices & Notes
Best Practices
- Remember the output can't distinguish the original character's case; if that matters, keep a copy of your original text alongside the keyCode output.
- When a character is rejected, treat that as useful information about keyCode's real limitations, not a bug to work around.
Developer Notes
The table is built programmatically for digits (48 + n) and letters (65 + n, both cases mapping to the same value), then extended with the 11 literal OEM virtual-key codes (186-192, 219-222) from the MDN reference table. keycodes-to-ascii-converter imports this exact table and inverts it (dropping lowercase letter entries first) to guarantee the two tools stay in sync.
ASCII to Keycodes Converter Use Cases
- Debugging or documenting legacy onkeydown/onkeyup handlers that branch on event.keyCode
- Building test fixtures that simulate specific historical keyCode values
- Teaching the difference between keyCode (a physical key number) and a character's actual ASCII code
Common Mistakes
- Assuming keyCode encodes the shifted character; it doesn't, both "a" and "A" produce the same keyCode.
- Expecting every printable ASCII character to have a keyCode; only the digits, letters, space, and 11 specific punctuation keys have one documented here.
Tips
- If you need the actual character each key produces including shift state, KeyboardEvent.key is the modern replacement and isn't something this legacy-focused tool attempts to model.
- Round-trip through Keycodes to ASCII Converter to see exactly how much case information keyCode loses.