I want terminal keypresses to Just Work. What do I mean Just Work? I mean programs in a simple orthogonal way, can determine the key that was pressed, and this model should easily map to the user's expectation.
Why doesn't it currently?
By having a sane and sensible model on BOTH ends of the terminal interaction, and a well-defined way of communicating. How exactly we go about this really depends who you are:
The simplest way to go about this is to use my terminal key input library, libtermkey. Failing this, if you're using some existing system of keyboard input, such as GNU Readline, I suggest you apply pressure to the maintainers of that system until they adopt this method of reading extended keypresses.
Making a terminal send the correct key encodings should be a relatively easy task, given the encoding scheme already splits modifiers and keysyms in a way likely to be similar to the underlying input system at work, such as X11 or Win32.
TODO: More on this later. Notetoself: libvterm does it too; paste example?
The primary motivation of this scheme is to encode any possible keypress uniquely; that a keypress maps to one possible sequence of bytes, and a valid sequence of bytes encodes only one keypress. For backward compability, it is also required that any keypress that can be represented without this scheme is also represented by the same bytes within it; that is, this scheme is an extension of existing encodings, not a replacement of.
CSI [codepoint];[modifier] uThe u CSI command lies in the private-use area, so has no fixed meaning at present.
CSI [number];[modifier] ~The modifier is value 1 + a bitmask encoding the modifiers. 1 for Shift, 2 for Alt, 4 for Ctrl.
CSI 1;[modifier] {ABCDFHPQRS}
TODO: The above can be made a lot more precise, into a big table explaining the bytes to send for classes of key + modifier combinations. Too much detail here? Perhaps..
Advantages: solves above problems. Can be fitted into existing programs with a minimum of fuss and without breaking back-compat.
Extension: Can take it one step further, and require CSI to be sent as 8bit code, never as 7bit Esc [. Is unambiguous wrt. well-formed UTF-8. Can then reserve Esc exclusively for the real Escape key. Hey presto - no need to rely on timing information.