ASCII to Scan Codes Converter
Convert ASCII characters to PS/2 Set 1, Set 2, and USB HID scan codes. Supports batch conversion, reverse lookup, and export.
| Char | ASCII Dec | ASCII Hex | PS/2 Set 1 | PS/2 Set 2 | USB HID | Modifier | Key Name |
|---|
About
Keyboard scan codes are the raw hardware-level identifiers sent by a keyboard controller to the host system. They differ fundamentally from ASCII values. A PS/2 keyboard using Set 1 (XT) sends 0x1E for the A key, while Set 2 (AT) sends 0x1C for the same physical key. USB HID keyboards use an entirely separate Usage ID table defined in the USB HID Usage Tables specification (Document v1.4). Confusing these code spaces is the most common source of bugs in firmware development, OS kernel input drivers, and bootloader keyboard handlers. This tool maps all 128 standard ASCII code points (0 - 127) to their corresponding PS/2 Set 1 Make code, PS/2 Set 2 Make code, and USB HID Usage ID. Extended codes (E0-prefixed) for keys like arrows or Insert are included where applicable.
Limitations: this mapping assumes a US QWERTY layout. Shifted characters (e.g., ! at 0x21) map to the base key’s scan code plus a Shift modifier flag. Non-printable control characters (0x00 - 0x1F) are mapped to their conventional key equivalents where a direct physical key exists (e.g., Tab, Enter, Escape, Backspace). Characters with no standard single-key mapping are marked accordingly.
Formulas
The conversion is a direct lookup operation. No arithmetic formula is involved. Each ASCII code point c is used as an index into a mapping table T that returns a tuple of scan codes:
Where S1 = PS/2 Set 1 Make code, S2 = PS/2 Set 2 Make code, U = USB HID Usage ID, and m = modifier flag (Shift required: TRUE or FALSE). For uppercase letters and shifted symbols, the base key scan code is returned with m = TRUE, indicating the host must also send/register the Shift modifier (PS/2 Set 1: 0x2A, USB HID: 0xE1). The valid domain is c ∈ [0, 127] ⊂ Z. Values outside this range produce no mapping.
Reference Data
| ASCII | Dec | Hex | Char | PS/2 Set 1 (Make) | PS/2 Set 2 (Make) | USB HID | Key Name |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0x00 | NUL | - | - | 0x00 | No Event |
| 8 | 8 | 0x08 | BS | 0x0E | 0x66 | 0x2A | Backspace |
| 9 | 9 | 0x09 | TAB | 0x0F | 0x0D | 0x2B | Tab |
| 13 | 13 | 0x0D | CR | 0x1C | 0x5A | 0x28 | Enter |
| 27 | 27 | 0x1B | ESC | 0x01 | 0x76 | 0x29 | Escape |
| 32 | 32 | 0x20 | SP | 0x39 | 0x29 | 0x2C | Space |
| 48 | 48 | 0x30 | 0 | 0x0B | 0x45 | 0x27 | 0 Key |
| 49 | 49 | 0x31 | 1 | 0x02 | 0x16 | 0x1E | 1 Key |
| 50 | 50 | 0x32 | 2 | 0x03 | 0x1E | 0x1F | 2 Key |
| 57 | 57 | 0x39 | 9 | 0x0A | 0x46 | 0x26 | 9 Key |
| 65 | 65 | 0x41 | A | 0x1E | 0x1C | 0x04 | A Key |
| 66 | 66 | 0x42 | B | 0x30 | 0x32 | 0x05 | B Key |
| 67 | 67 | 0x43 | C | 0x2E | 0x21 | 0x06 | C Key |
| 87 | 87 | 0x57 | W | 0x11 | 0x1D | 0x1A | W Key |
| 88 | 88 | 0x58 | X | 0x2D | 0x22 | 0x1B | X Key |
| 89 | 89 | 0x59 | Y | 0x15 | 0x35 | 0x1C | Y Key |
| 90 | 90 | 0x5A | Z | 0x2C | 0x1A | 0x1D | Z Key |
| 97 | 97 | 0x61 | a | 0x1E | 0x1C | 0x04 | A Key |
| 122 | 122 | 0x7A | z | 0x2C | 0x1A | 0x1D | Z Key |
| 127 | 127 | 0x7F | DEL | E0 53 | E0 71 | 0x4C | Delete |