Colleagues, please help me solve one problem.
Many years ago, I wrote my own command line editor because the existing ones lacked the functionality I needed.
The editor requests the necessary sequences of keyboard codes and screen control sequences from terminfo. Then it builds a sorted list from the keyboard codes.
The keyboard codes received during the work are collected in a certain buffer and constantly checked against the sorted list. After a match, it interprets the received key and performs the necessary actions.
Now I needed to add a handler for the ESC key and I discovered a paradoxical thing. The key does not send some unambiguous sequence that does not conflict with others, but the ESC code itself (0x1b).
For example, this is what the F1 key sends
And this is ESC key itself.
A huge logical ambiguity arises. Almost all keyboard code sequences begin with the ESC symbol (0x1b). I still don't understand how to distinguish a "single" ESC key from the beginning of a sequence.
Please tell me how to solve my problem.
Thank you for the answers to the point,
Ogogon.
Many years ago, I wrote my own command line editor because the existing ones lacked the functionality I needed.
The editor requests the necessary sequences of keyboard codes and screen control sequences from terminfo. Then it builds a sorted list from the keyboard codes.
The keyboard codes received during the work are collected in a certain buffer and constantly checked against the sorted list. After a match, it interprets the received key and performs the necessary actions.
Now I needed to add a handler for the ESC key and I discovered a paradoxical thing. The key does not send some unambiguous sequence that does not conflict with others, but the ESC code itself (0x1b).
For example, this is what the F1 key sends
Code:
ogogon@devel# ./kprint
{0x1b:'ESC'}{0x4f:'O'}{0x50:'P'}
ogogon@devel#
And this is ESC key itself.
Code:
ogogon@devel# ./kprint
{0x1b:'ESC'}
ogogon@devel#
A huge logical ambiguity arises. Almost all keyboard code sequences begin with the ESC symbol (0x1b). I still don't understand how to distinguish a "single" ESC key from the beginning of a sequence.
Please tell me how to solve my problem.
Thank you for the answers to the point,
Ogogon.