4

According to this table of terminal emulators and their keycodes, new versions of XTerm recognize function keys from F1, F2, F3, ... all the way up to F63. Most keyboards only have physical function keys in the range F1..F12. What is the purpose of the extra keys? Is there some (semi-)standard mapping from physical key or mouse presses to those function key numbers, and if not, how are they triggered?

I'm under the impression that in traditional terminal parlance, all special keys including the arrow keys, home/end, etc. were called function keys (whereas those of us who grew up on PCs would consider only F1..F12 to be function keys). But then, XTerm also talks separately about these named keys (e.g. kUP for the up arrow key in that table).

6

DEC VTs represent function keys and various cursor and editing keys with a control sequence named DECFNK, which is CSI followed by one or two parameters followed by ~. The first parameter is the function key number. The second parameter indicates active modifier key states.

As far as DECFNK is concerned, there can be up to 20 function keys. The DECFNK codes for function keys 1 to 20 are well-defined and documented. There were, after all, physically 20 function keys on the LK keyboards. (Even if several function keys usually did not, they could potentially all generate DECFNK sequences, and the sequences are in the DEC doco.) Here's an LK401 keyboard for a DEC VT420:

An LK401 keyboard

As you can see in your table, the emulators that produce the original DECFNK sequences emit DECFNK 11 to DECFNK 34 for these 20 keys. (Some of the DECFNK numbers are skipped. Interestingly, the skipped numbers correspond to the physical spaces between the key groups of the function key row on the keyboard.)

Where things get complex is where the PC and XENIX were introduced. In the world of the IBM PC, and in particular the PC 3270, there were 24 function keys on the Model F keyboards. The PC/AT's Enhanced keyboard had 12 function keys, half that. Here is a 3270 Model F keyboard:

A 122-key IBM Model F keyboard

Terminal emulation conventions arose that the function keys from F13 to F24 could be accessed from a PC/AT keyboard by using combinations of modifiers. With the four combinations of ⎈ Control and ⇧ Level 2 Shift, the mere 12 function keys on an Enhanced keyboard could be made to simulate 48 function keys. This was the case for the XENIX console, which generated 48 distinct control sequences.

You will observe in the other columns of that table that that is what is happening. The control sequences for (say) F6, F18, F30, and F42 are all DECFNK 17 with different values for the modifier bitflags in the second parameter.

Also observe that F1 to F5 are not DECFNK control sequences in those same columns. This is again down to emulator conventions on PC keyboards. On the DEC LK keyboards, F1 to F5 did have assigned DECFNK sequences and could generate them, but usually operated in a "local" mode where they did not generate input to the host. Emulators did not need to generate these DECFNK sequences and emulate F1 to F5, because few to no applications relied upon these keys as a consequence; but emulators conversely did need to emulate a set of PF1 to PF4 keys that were on the calculator keypad in an actual DEC keyboard, but that PC keyboards did not have. These keys did not generate DECFNK sequences, and weren't true function keys. They generated SS3 control sequences, like the other calculator keys.

(Some of the SS3 sequences are malformed. "SS" stands for "Single Shift" and such shifts apply to a single following character. The XTerm control sequences that append modifier parameters to SS3 are not in fact correctly formed SS3 sequences. Real DEC terminals did not work this way. Modifiers were not reported for calculator key control sequences.)

This explains how the function key control sequence set for emulated terminals can go as high as 48 function keys. To explain 64 control sequences, one simply needs to notice the modifier parameter in the DECFNK sequences. For the additional 12 control sequences it is 3, which denotes the ⎇ Alt modifier.

In fact, there are 8 possible combinations of ⎈ Control, ⇧ Level 2 Shift, and ⎇ Alt; the three modifiers recognized by the DEC VT control sequence protocol. There can thus be 96 different DECFNK control sequences per these terminal emulator conventions from a PC/AT Enhanced keyboard, and 160 from a DEC LK keyboard.

Further reading

4

xterm actually supports far more than 64 function-keys (by shift, control, alt, meta modifiers). The 64 happens to be the portable set defined in terminfo (and part of X/Open Curses). The first one in the set is kf0 (which confuses people, so it is seldom used).

It does this, because people wanted to be able to distinguish the various key combinations (not everyone is an emacs user, but that helps). Without inventing a whole new set of terminfo capabilities, extending xterm to use the available predefined 64 terminfo names was a good enough solution.

With ncurses' user-defined keys, the xterm terminal description has more than that, but still less than the actual limit. Multiplying out the combinations, for just the PC-keyboard's 12 keys, that's 8*12 or 16*12, depending on whether your configuration equates alt and meta.

The same set of modifiers applies to the 4 cursor keys and the 6 editing-keys.

The modifiers in turn can be modified (giving different sets of escape sequences). The various building blocks in xterm's terminfo source illustrate those (such as xterm+pcf0, xterm+pcf1, etc.), multiplying the possibilities.

But no one's counting...

By the way, a real VT220 didn't do anything (useful) with the first 5 function keys, by default. But that's a different story.

As for PC's, using shift/control/alt for modifiers is old. ncurses has some terminal descriptions for OS/2 using that approach, as well as SCO (same hardware).

2

It has to do with the old DEC ascii terminals such as VT220.

http://www.columbia.edu/kermit/k95vtfk.html

The function keys were used for interacting with text based programs that ran on mainframe computers.

The connection between the terminal and the mainframe was usually serial.

Pressing an F key caused the terminal to transmit a sequence of ASCII codes, usually starting with the ESC character.

The F keys were similar to hotkeys in modern computer usage.

For example, F1 could be a key that brought up a menu on the screen.

Combination of the shift and control keys along with the F keys would generate the F21-F64

For example, F21 would be generated by pressing shift-F1. (may have been ctrl-F1) F61 would be something like ctrl-shft-F1

  • A Sun 4 keyboard had more function keys that your typical PC keyboard. It is too bad your email is private. I could have sent you better photos – Basile Starynkevitch 2 days ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.