ANSI/DEC VT Terminal Keycode Sequences ====================================== Sorted by keycode sequence -------------------------- +----------+----------+----------+------------+-------------------+-------------+-----+ | | UKNC/15 | UKNC/52 | VT52 | VT100 | VT220/xterm |Reglr| +----------+----------+----------+------------+-------------------+-------------+-----+ | f9/Insert| <08> | | | | | 008 | | BS | | | <08> | <08> | <08> | 008 | | TAB | <09> | <09> | <09> | <09> | <09> | 009 | | LF | | | <0A> | <0A> | | 00A | | Return | <0D><0A> | <0D><0A> | <0D> | <0D> | <0D> | 00D | | Right | <19> | | | | | 1CD | | Left | <1A> | | | | | 1CC | | Escape | | | | | | 01B | | Up | <1C> | | | | | 1CF | | Down | <1D> | | | | | 1CE | | SPC | <20> | <20> | <20> | <20> | <20> | 020 | | f12/Home | <5F> | <5F> | | | | 05F | | BS | <7F> | <7F> | | | | 07F | | | | | | | | | | Up | | A | A | [A OA | [A | 1CF | | Down | | B | B | [B OB | [B | 1CE | | Right | | C | C | [C OC | [C | 1CD | | Left | | D | D | [D OD | [D | 1CC | | Begin | | | |(OE [E)|([E) | 1C5 | | End | | | | | F (HP) | 1C9 | | sKP5 | | | | [G | [G | | | Home | | | | | OH | 1C8 | | f9/Ins | | H | | | | | | | | | | | | | | Clear | | | | | J (HP) | | | cDown | | J | | | | 1EE | | cRight | | K | | | | 1ED | | | | | | | | | | KPent | | | ?M | OM | OM | 10D | | | | | | | | | | f1/PF1 | P | P | P | OP | OP | 181 | | f2/PF2 | Q | Q | Q | OQ | OQ | 182 | | f3/PF3 | R | R | R | OR | OR | 183 | | f4/PF4 | S | S | S | OS | OS | 184 | | f5 | T | T | T | OT | | 185 | | f6 | | | | OU | | 186 | | f7 | | | | OV | | 187 | | f8 | | | | OW | | 188 | | f9 | | | | OX | | 189 | | KP= | | | | OX | OX | 13D | | f10 | | | | OY | | 18A | | f11/sf1 | | | | OZ | | 18B | | sTAB | | | | [Z | [Z | 1D5 | | f12/sf2 | | | | O[ | | 18C | | | | | | | | | | KP* | | | |(Oj) | | 12A | | KP+ | | | |(Ok) | | 12B | | KP, | | |(?l) | Ol | Ol | 12C | | KP- | | |(?m) | Om | Om | 12D | | KP. | | | ?n | On | On | 12E | | KP/ | | | ?o | Oo | Oo | 12F | | KP0 | | | ?p | Op | Op | 130 | | KP1 | | | ?q | Oq | Oq | 131 | | KP2 | | | ?r | Or | Or | 132 | | KP3 | | | ?s | Os | Os | 133 | | KP4 | | | ?t | Ot | Ot | 134 | | KP5 | | | ?u | Ou | Ou | 135 | | KP6 | | | ?v | Ov | Ov | 136 | | KP7 | | | ?w | Ow | Ow | 137 | | KP8 | | | ?x | Ox | Ox | 138 | | KP9 | | | ?y | Oy | Oy | 139 | | | | | | | | | | f6/Delete| ~ | ~ | | | | 186 | | f8/PgDn | <7F>| <7F>| | | | 188 | | | | | | | | | | f1 | | | | [[A | | 181 | | f2 | | | | [[B | | 182 | | f3 | | | | [[C | | 183 | | f4 | | | | [[D | | 184 | | f5 | | | | [[E | | 185 | | | | | | | | | | Find | | | | | [1~ | 1C8 | | Home | | | | | [1~ | 1C8 | | Insert | | | | | [2~ | 1C6 | | Delete | | | | | [3~ | 1C7 | | Remove | | | | | [3~ | 1C7 | | End | | | | | [4~ | 1C9 | | Select | | | | | [4~ | 1C9 | | PgUp/Prev| | | | | [5~ | 1CB | | PgDn/Next| | | | | [6~ | 1CA | |(Home) | | | | | [7~ | 1C8 | |(End) | | | | | [8~ | 1C9 | |(NumLk) | | | | | [9~ | 18D | | | | | | | | | | f0 | | | | | [10~ | 180 | | f1 | | | | | [11~ | 181 | | f2 | | | | | [12~ | 182 | | f3 | | | | | [13~ | 183 | | f4 | | | | | [14~ | 184 | | f5 | | | | | [15~ | 185 | | | | | | | | | | f6 | | | | | [17~ | 186 | | f7 | | | | | [18~ | 187 | | f8 | | | | | [19~ | 188 | | f9 | | | | | [20~ | 189 | | f10 | | | | | [21~ | 18A | | | | | | | | | | f11 | | | | | [23~ | 18B | | f12 | | | | | [24~ | 18C | | f13/sf3 | | | | | [25~ | 18D | | Scrl/Prnt| | | | | [25~ | 180 | | f14/sf4 | | | | | [26~ | 18E | | | | | | | | | | f15/Break| | | | | [28~ | 18F | | f15/sf5/Help | | | | [28~ | 18F | | f16/sf6/Menu | | | | [29~ | 1C1 | | f17/sf7 | | | | | [31~ | | | f18/sf8 | | | | | [32~ | | | f19/sf9 | | | | | [33~ | | | f20/sf10 | | | | | [34~ | | | | | | | | | | +----------+----------+----------+------------+-------------------+-------------+-----+ should be ignored until non- received has zero parameters eg A B ? has zero parameters eg ?P ?q O has zero parameters eg OP Oq [[ has zero parameters eg [[A [[B [... has zero or one parameter eg [A [2B [...~ has one or two parameters eg [10~ 20;2~ The parameters are: [() eg [A [2B [(;)~ eg [10~ [20;2~ Sorted for optimised lookup --------------------------- +----------+---+----------+----------+------------+-------------------+-------------+-----+ | | | UKNC/15 | UKNC/52 | VT52 | VT100 | VT220 |Reglr| +----------+---+----------+----------+------------+-------------------+-------------+-----+ | Right | | 19 | | | | | 1CD | | Left | | 1A | | | | | 1CC | | Escape | | | | | | | 01B | | Up | | 1C | | | | | 1CF | | Down | | 1D | | | | | 1CE | +----------+---+----------+----------+------------+-------------------+-------------+-----+ Table 1 +----------+---+----------+----------+------------+-------------------+-------------+-----+ | | @ | | | | | | | | Up | A | | A | A | [A OA | [A | 1CF | | Down | B | | B | B | [B OB | [B | 1CE | | Right | C | | C | C | [C OC | [C | 1CD | | Left | D | | D | D | [D OD | [D | 1CC | | Begin | E | | | | OE [E | [E | 1C5 | | End | F | | | | | F | 1C9 | | sKP5 | G | | | | [G | [G | | | Home | H | | | | | OH | 1C8 | | | I | | | | | | | | cDown | J | | J | | | | 1EE | | cRight | K | | K | | | | 1ED | | | L | | | | | | | | KPent | M | | | ?M | OM | OM | 10D | | | N | | | | | | | | | O | | | | | | | | f1/PF1 | P | P | P | P | OP [[A | OP | 181 | | f2/PF2 | Q | Q | Q | Q | OQ [[B | OQ | 182 | | f3/PF3 | R | R | R | R | OR [[C | OR | 183 | | f4/PF4 | S | S | S | S | OS [[D | OS | 184 | | f5 | T | T | T | T | OT [[E | | 185 | | f6 | U | | | | OU | | 186 | | f7 | V | | | | OV | | 187 | | f8 | W | | | | OW | | 188 | | f9 | X | | | | OX | | 189 | | f10 | Y | | | | OY | | 18A | | f11 | Z | | | | OZ | | 18B | | sTAB | Z | | | | [Z | [Z | 1D5 | | f12 | [ | | | | O[ | | 18C | | | \ | | | | | | | | | ] | | | | | | | | | ^ | | | | | | | | | _ | | | | | | | | | ` | | | | | | 120 | | | a | | | | | | 121 | | | b | | | | | | 122 | | | c | | | | | | 123 | | | d | | | | | | 124 | | | e | | | | | | 125 | | | f | | | | | | 126 | | | g | | | | | | 127 | | | h | | | | | | 128 | | | i | | | | | | 129 | | KP* | j | | | | Oj | | 12A | | KP+ | k | | | | Ok | | 12B | | KP, | l | | | ?l | Ol | Ol | 12C | | KP- | m | | | ?m | Om | Om | 12D | | KP. | n | | | ?n | On | On | 12E | | KP/ | o | | | ?o | Oo | Oo | 12F | | KP0 | p | | | ?p | Op | Op | 130 | | KP1 | q | | | ?q | Oq | Oq | 131 | | KP2 | r | | | ?r | Or | Or | 132 | | KP3 | s | | | ?s | Os | Os | 133 | | KP4 | t | | | ?t | Ot | Ot | 134 | | KP5 | u | | | ?u | Ou | Ou | 135 | | KP6 | v | | | ?v | Ov | Ov | 136 | | KP7 | w | | | ?w | Ow | Ow | 137 | | KP8 | x | | | ?x | Ox | Ox | 138 | | KP9 | y | | | ?y | Oy | Oy | 139 | | | z | | | | | | 13A | | | { | | | | | | 13B | | | | | | | | | | 13C | | | } | | | | | | 13D | | f6/Delete| ~ | ~ | ~ | | | [0~ | 186 | | f8/PgDn |DEL| <7F>| <7F>| | | | 188 | +----------+---+----------+----------+------------+-------------------+-------------+-----+ Table 2 +----------+----+---------+----------+------------+------------------+--------------+-----+ | | | UKNC/15 | UKNC/52 | VT52 | VT100 | VT220/xterm |Reglr| +----------+----+---------+----------+------------+------------------+--------------+-----+ | f6/Delete| 0 | ~ | ~ | | | [0~ | 186 | | Home/Find| 1 | | | | | [1~ | 1C8 | | Insert | 2 | | | | | [2~ | 1C6 | | Delete | 3 | | | | | [3~ | 1C7 | |End/Select| 4 | | | | | [4~ | 1C9 | |PgUp/Prev | 5 | | | | | [5~ | 1CB | |PgDn/Next | 6 | | | | | [6~ | 1CA | | (Home) | 7 | | | | | [7~ | 1C8 | | (End) | 8 | | | | | [8~ | 1C9 | | (NumLk) | 9 | | | | | [9~ | 18D | | f0 | 10 | | | | | [10~ | 180 | | f1 | 11 | | | | | [11~ | 181 | | f2 | 12 | | | | | [12~ | 182 | | f3 | 13 | | | | | [13~ | 183 | | f4 | 14 | | | | | [14~ | 184 | | f5 | 15 | | | | | [15~ | 185 | | | 16 | | | | | [16~ | | | f6 | 17 | | | | | [17~ | 186 | | f7 | 18 | | | | | [18~ | 187 | | f8 | 19 | | | | | [19~ | 188 | | f9 | 20 | | | | | [20~ | 189 | | f10 | 21 | | | | | [21~ | 18A | | | 22 | | | | | [22~ | | | f11 | 23 | | | | | [23~ | 18B | | f12 | 24 | | | | | [24~ | 18C | | f13/Print| 25 | | | | | [25~ | 180 | | f14/Scrll| 26 | | | | | [26~ | 18E | | | 27 | | | | | [27~ | | | f15/Break| 28 | | | | | [28~ | 18F | | f16/Menu | 29 | | | | | [29~ | 1C1 | | | 30 | | | | | [30~ | | | f17 | 31 | | | | | [31~ | | | f18 | 32 | | | | (Print) | [32~ | 180 | | f19 | 33 | | | | (Cancel) | [33~ | | | f20 | 34 | | | | (Pause) | [34~ | 18F | +----------+----+---------+----------+------------+------------------+--------------+-----+ Decoding process ---------------- Parsing input from an ANSI keyboard stream can be optimised by combining all keycode sequences into a superset that represents all sources: [() (;) or '~' or ? identical to O or where: is taken to mean '@' (CHR$64) to (CHR$127), and is taken to mean '@' (CHR$64) to '_' (CHR$95). and is one or more of CHR$27 The input stream can be parsed as: <---------------------------+ --> loop until non----+ '[' --> parse numbers --> terminator = '~' --->---YES-------> Table 2 | +-->--NO--> modifier= '?' --> get char -\ | 'O' --> get char --+--> no modifier ->-----------+----------> Table 1 --------------/ --------------------------------------------------------> Example code: * JGH Console Library - mdfs.net/System/C/Lib * PDP11 ANSI parsing - mdfs.net/Info/Comp/PDP11/ProgTips References ---------- * invisible-island.net/xterm/ctlseqs/ctlseqs.html * www.xfree86.org/current/ctlseqs.html * www.gnu.org/software/screen/manual/html_node/Input-Translation.html#Input-Translation Updates ------- 22-Jun-2020: Testing suggests malformed sequences are ignored. Slight formatting changes. 08-Mar-2024: Testing with latest version of puTTY. Sorted by regular keycode ------------------------- +----------+----------+----------+------------+------------------+---------------+-------+ | | UKNC/15 | UKNC/52 | VT52 | VT100 | VT220/xterm |Regular| +----------+----------+----------+------------+------------------+---------------+-------+ | f9/Insert| 08 | | | | | 008 | | BS | 7F | 7F | 08 | 08 | 08 | 008 | | TAB | 09 | 09 | 09 | 09 | 09 | 009 | | LF | | | 0A | 0A | | 00A | | Return | 0D 0A | 0D 0A | 0D | 0D | 0D | 00D | | SPC | 20 | 20 | 20 | 20 | 20 | 020 | | f12/Home | 5F | 5F | | | | 05F | | | | | | | | | | Escape | | | | | | 01B | | | | | | | | | | KPent | | | ? M | O M | O M | 10D | | Clear | | | | |(J) | 11B | | | | | | | | | | KP* | | | |(O j) | | 12A | | KP+ | | | |(O k) | | 12B | | KP, | | |(? l) | O l | O l | 12C | | KP- | | |(? m) | O m | O m | 12D | | KP. | | | ? n | O n | O n | 12E | |(KP/) | | | ? o | O o | O o | 12F | | KP0 | | | ? p | O p | O p | 130 | | KP1 | | | ? q | O q | O q | 131 | | KP2 | | | ? r | O r | O r | 132 | | KP3 | | | ? s | O s | O s | 133 | | KP4 | | | ? t | O t | O t | 134 | | KP5 | | | ? u | O u | O u | 135 | | KP6 | | | ? v | O v | O v | 136 | | KP7 | | | ? w | O w | O w | 137 | | KP8 | | | ? x | O x | O x | 138 | | KP9 | | | ? y | O y | O y | 139 | | KP= | | | | O X | O X | 13D | | | | | | | | | | f1/PF1 | P | P | P | O P | O P | 181 | | f2/PF2 | Q | Q | Q | O Q | O Q | 182 | | f3/PF3 | R | R | R | O R | O R | 183 | | f4/PF4 | S | S | S | O S | O S | 184 | | f5 | T | T | | | | 185 | | f6/Delete| ~ | ~ | | | | 186 | | f8/PgDn | 7F | 7F | | | | 188 | | f9/Insert| | H | | | | 189 | | Home | | | | O H | | 1C8 | | End | | | | O F | | 1C9 | | Next | | | | | [G | 1CA | | Left | 1A | D | D | O D | [D | 1CC | | Right | 19 | C | C | O C | [C | 1CD | | Down | 1D | B | B | O B | [B | 1CE | | Up | 1C | A | A | O A | [A | 1CF | | | | | | | | | | f0 | | | | | [1 0 ~ | 180 | | f1 | | | | | [1 1 ~ | 181 | | f2 | | | | | [1 2 ~ | 182 | | f3 | | | | | [1 3 ~ | 183 | | f4 | | | | | [1 4 ~ | 184 | | f5 | | | | | [1 5 ~ | 185 | | f6 | | | | | [1 7 ~ | 186 | | f7 | | | | | [1 8 ~ | 187 | | f8 | | | | | [1 9 ~ | 188 | | f9 | | | | | [2 0 ~ | 189 | | f10 | | | | | [2 1 ~ | 18A | | f11 | | | | | [2 2 ~ | 18B | | f12 | | | | | [2 4 ~ | 18C | | f13 | | | | | [2 5 ~ | 18D | | Print| | | | | [2 5 ~ | 180 | | f14/Scrll| | | | | [2 6 ~ | 18E | | f15/Break| | | | | [2 8 ~ | 18F | | | | | | | | | | Menu | | | | | [2 9 ~ | 1C1 | | Keypad-5 | | | | O E | [E | 1C5 | | Insert | | | | | [2 ~ | 1C6 | | Delete | | | | | [3 ~ | 1C7 | | Home | | | | | [1 ~ | 1C8 | | (Home) | | | | | [7 ~ | 1C8 | | End | | | | | [4 ~ | 1C9 | | (End) | | | | | [8 ~ | 1C9 | | PgDn | | | | | [6 ~ | 1CA | | PgUp | | | | | [5 ~ | 1CB | | | | | | | | | | f16 | | | | | [2 9 ~ | | | f17 | | | | | [3 1 ~ | | | f18 | | | | | [3 2 ~ | | | f19 | | | | | [3 3 ~ | | | f20 | | | | | [3 4 ~ | | +----------+----------+----------+------------+------------------+---------------+-------+ Sorted by keypress ------------------ +--------+----------+----------+------------+-------------------+-----------------+-----+ | | UKNC/15 | UKNC/52 | VT52 | VT100 | VT220/xterm |Reglr| +--------+----------+----------+------------+-------------------+-----------------+-----+ | BS | <7F> | <7F> | <08> | <08> | <08> | 008 | | sBS | <7F> | <7F> | | <7F> | <7F> | 07F | | TAB | <09> | <09> | <09> | <09> | <09> | 009 | | sTAB | <09> | <09> | | [Z | [Z | 1D5 | | LF | | | <0A> | <0A> | | 00A | | Return | <0D><0A> | <0D><0A> | <0D> | <0D> | <0D> | 00D | | Escape | | | | | | 01B | | SPC | <20> | <20> | <20> | <20> | <20> | 020 | | Menu | <0E><0F> | <0E><0F> | | | | | | | | | | | | | | Up | <1C> | A | A | [A OA | [A | 1CF | | Down | <1D> | B | B | [B OB | [B | 1CE | | Right | <19> | C | C | [C OC | [C | 1CD | | Left | <1A> | D | D | [D OD | [D | 1CC | | sUp | | A | | [1;2A | [1;2A | 1DF | | sDown | | B | | [1;2B | [1;2B | 1DE | | sRight | | C | | [1;2C | [1;2C | 1DD | | sLeft | | D | | [1;2D | [1;2D | 1DC | | cUp | <1C> | A | | [1;5A | [1;5A | 1EF | | cDown | <1D> | J | | [1;5B | [1;5B | 1EE | | cRight | <19> | K | | [1;5C | [1;5C | 1ED | | cLeft | <1A> | D | | [1;5D | [1;5D | 1EC | | +Alt | | | | [1;3 | [1;3 | 1Fx | | | | | | | | | | Begin | | | |(OE [E)|([E) | 1C5 | | Find | | | | | [1~ | 1C8 | | Remove | | | | | [3~ | 1C7 | | Select | | | | | [4~ | 1C9 | | Prev | | | | | [5~ | 1CB | | Next | | | | | [6~ | 1CA | | Help | | | | | [28~ | 18F | | Menu | | | | | [29~ | 1C1 | | End | | | | | F (HP) | 1C9 | | Clear | | | | | J (HP) | 11B | | End | | | | | OF | 1C9 | | Home | | | | | OH | 1C8 | | | | | | | | | | Home | <5F> | <5F> | H? | [1~ OH? | [1~ | 1C8 | | Insert | <08> | H | | [2~ | [2~ | 1C6 | | Delete | ~ | ~ | <7F> | [3~ | [3~ | 1C7 | | End | | | F? | [4~ OF? | [4~ | 1C9 | | PgUp | | | | [5~ | [5~ | 1CB | | PgDn | <7F>| <7F>| | [6~ | [6~ | 1CA | |(Home) | | | | | [7~ | 1C8 | |(End) | | | | | [8~ | 1C9 | |(NumLk) | | | | | [9~ | 18D | | sHome | | <7F> | | [1;2~ | [1;2~ | 1D8 | | sInsert| | J | | [2;2~ | [2;2~ | 1D6 | | sDelete| | ~ | | [3;2~ | [3;2~ | 1D7 | | sEnd | | | | [4;2~ | [4;2~ | 1D9 | | sPgUp | | | | [5;2~ | [5;2~ | 1DB | | sPgDn | | <7F>| | [6;2~ | [6;2~ | 1DA | | cHome | | <1F> | | [1;5~ | [1;5~ | 1E8 | | cInsert| | <0C> | | [2;5~ | [2;5~ | 1E6 | | cDelete| | | | [3;5~ | [3;5~ | 1E7 | | cEnd | | | | [4;5~ | [4;5~ | 1E9 | | cPgUp | | | | [5;5~ | [5;5~ | 1EB | | cPgDn | | | | [6;5~ | [6;5~ | 1EA | | +Alt | | | | [;3~ | [;3~ | 1Fx | | | | | | | | | | PF1 | | | P | OP | OP | 181 | | PF2 | | | Q | OQ | OQ | 182 | | PF3 | | | R | OR | OR | 183 | | PF4 | | | S | OS | OS | 184 | | | | | | | | | |(f0) | | | | Oy Oq |([10~) | 180 | | | | | | Linux: | | | | f1 | P | P | P | OP [[A | [11~ | 181 | | f2 | Q | Q | Q | OQ [[B | [12~ | 182 | | f3 | R | R | R | OR [[C | [13~ | 183 | | f4 | S | S | S | OS [[D | [14~ | 184 | | f5 | T | T | T | OT [[E | [15~ | 185 | | f6/Del | ~ | ~ | | OU | [17~ | 186 | | f7 | | | | OV | [18~ | 187 | | f8/PgDn| <7F>| <7F>| | OW | [19~ | 188 | | f9/Ins | <08> | H | | OX | [20~ | 189 | | f10 | | | | OY | [21~ | 18A | | f11 | | | | OZ | [23~ | 18B | | f12 | <5F> | <5F> | | O[ | [24~ | 18C | | f13 | | | | | [25~ | 18D | | f14 | | | | | [26~ | 18E | | f15/Help | | | | [28~ | 18F | | f16/Menu | | | | [29~ | 1C1 | | f17 | | | | | [31~ | | | f18 | | | | | [32~ | | | f19 | | | | | [33~ | | | f20 | | | | | [34~ | | | sf1 | | | | OZ | sf2 | | | | O[ | sf3 | | | | [25~ | sf4 | | | | [26~ | sf5 | | | | [28~ | sf6 | | | | [29~ | sf7 | | | | [31~ | sf8 | | | | [32~ | sf9 | | | | [33~ | sf10 | | | | [34~ | sf11 | | | | OZ | sf12 | | | | O[ | +Shift | | | | =+10 | [;2~ | 19x | | +Ctrl | | | | = | [;5~ | 1Ax | | +Alt | | | | = | [;3~ | 1Bx | | | | | | | | | | sKP5 | | | | [G | [G | | | KPent | | | ?M | OM | OM | 10D | | KP= | | | | OX | OX | 13D | | | | | | | | | | KP* | | | |(Oj) | | 12A | | KP+ | | | |(Ok) | | 12B | | KP, | | |(?l) | Ol | Ol | 12C | | KP- | | |(?m) | Om | Om | 12D | | KP. | | | ?n | On | On | 12E | | KP/ | | | ?o | Oo | Oo | 12F | | KP0 | | | ?p | Op | Op | 130 | | KP1 | | | ?q | Oq | Oq | 131 | | KP2 | | | ?r | Or | Or | 132 | | KP3 | | | ?s | Os | Os | 133 | | KP4 | | | ?t | Ot | Ot | 134 | | KP5 | | | ?u | Ou | Ou | 135 | | KP6 | | | ?v | Ov | Ov | 136 | | KP7 | | | ?w | Ow | Ow | 137 | | KP8 | | | ?x | Ox | Ox | 138 | | KP9 | | | ?y | Oy | Oy | 139 | +--------+----------+----------+------------+-------------------+-----------------+-----+