magmax / python-readchar

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

This library should include a disclaimer about the suggested use #50

Open rogerdahl opened 4 years ago

rogerdahl commented 4 years ago

This applies primarily for reading extended keys, such as the arrow keys, F-keys, Page Up/Down, Home, Insert, Delete, and most or all modifier key combinations.

The library is suggesting that the returned escape codes can be used directly for determining which keys were pressed, but that's not the case for Linux.

On Linux, the key escape codes should not be compared with hard coded values. That will only work if the end user's terminal emulator emits the same escape codes as the ones that are being checked against.

There is a list of captured escape codes included in the library and this should not be used for the same reason. It will only work if the end user's terminal emulator is emitting the same codes as the library author's terminal did.

The codes that the Python program will receive on a given user's machine are indicated by the TERM variable, which is usually set by the terminal emulator. Command line programs use the TERM variable to query the terminfo database to find which escape codes to expect for the various keys.

If things don't work as expected, many terminal emulators have settings (maybe under "compatibility"), where the codes can be adjusted to accommodate for programs that assume specific codes, such as this library does, and likely most programs that use it, do.