magmax / python-readchar

Python library to read characters and key strokes
MIT License
143 stars 45 forks source link

multiple variations of escape sequences #24

Open suresttexas00 opened 7 years ago

suresttexas00 commented 7 years ago

We have another problem. There are many keys that have different escape sequences, depending not only on distro (of linux), but even whether or not one is in a TTY session or a term window on the desktop:

for instance these:

# these are correct in a gnome term window or a PyCharm window:
F1 = '\x1b\x4f\x50'
F2 = '\x1b\x4f\x51'
F3 = '\x1b\x4f\x52'
F4 = '\x1b\x4f\x53'
F5 = '\x1b\x5b\x31\x35\x7e'

# in a TTY session these are the correct values!
F1_1 = '\x1b\x5b\x5b\x41'
F2_1 = '\x1b\x5b\x5b\x42'
F3_1 = '\x1b\x5b\x5b\x43'
F4_1 = '\x1b\x5b\x5b\x44'
F5_1 = '\x1b\x5b\x5b\x45'

This makes our situation even worse. I can only imagine the problems that may exist when we add windows in the equation. This may explain issues like #14, since this issue also affects page keys and home/end as well...

We run into more problems with F11 and F12 because of these mappings:

F11_1 = '\x1b\x5b\x32\x33\x7e'  # tty
F11 =     '\x1b\x5b\x32\x33\x7e\x1b'  # gnome
F12_1 = '\x1b\x5b\x32\x34\x7e'  # tty
F12 =     '\x1b\x5b\x32\x34\x7e\x08'  #gnome

As you see, the \x1b\x5b\x32\x34\x7e is also (or needs to be) in ESCAPE_SEQUENCES. So we have the same problem as the lone ESC key... another key must be pressed to return the sequence (if we are in a TTY).

More details of how keys are variously interpreted depending on what 'layer' of the OS one is dealing with (and a few other informational tidbits) were found at this discussion:

https://www.zsh.org/mla/users/2014/msg00273.html