Taking ESC keystroke apart from ESC sequence (reliable way)

Taking ESC keystroke apart from ESC sequence (reliable way)

Post by Jacques Gelin » Sat, 13 Jun 1992 02:39:11



I have written a text editor.
I am looking for a reliable way to differentiate between a single
Esc Keystroke and an Escape sequence generated by a special key (arrow
function key etc...).

This problem seams trivial, and I solved a years ago on a SCO UNIX
V.3.2. Here is a sample of code. This code is in a process that do only
this. It reads keystroke and pipe it to another process and back in input.

        // Do some modification to the UNIX Terminal setting
        struct termio tchange;
        ioctl(0,TCGETA,&tchange);
        tchange.c_lflag=0;
        tchange.c_iflag=IGNBRK|IGNPAR;
        tchange.c_cc[VMIN]=1;
        tchange.c_cc[VTIME]=1;
        ioctl(0,TCSETA,&tchange);
        baud_delai = twice the reception time of a single character
                                 (based on baud rate)
        while (1){
                char array[10];
                int nb = read (0,array,10);
                // This return as soon as one byte is available, waiting a little
                // for the remaining 9.
                if (array[0] == 27){
                        // Checks for more, with a timeout
                        fd_set inset;
                        struct timeval timeout;
                        timeout.tv_sec = 0;
                        timeout.tv_usec = baud_delai;
                        memset (&inset,0,sizeof(inset));
                        FD_SET  (handle,&inset);
                        if (select (1,&inset,NULL,NULL,uvtimeout == 0 ? NULL : &timeout) > 0){
                                nb += read (0,array+1,9);
                        }
                }
                // nb holds the number of byte in array
                // Send the stuff to the other process.
        }

Then I have ported this to SUNOS.
This code works well with on SUNOS, with some exception. I get equivalent
results using poll(). If you are operating in a xterm, this works fine. From
there you do a rlogin to another workstation, and exec the program. Then
the program see escape sequence as an escape keytroke and a sequence. I have
tried to increase the delai. It helps a little bit, but is unreliable.

There must be a better way to do this, because vi has no problem.

Any clue!

--

--------------------------------------------------------

Today it's my opinion

 
 
 

Taking ESC keystroke apart from ESC sequence (reliable way)

Post by Alex Martel » Sun, 21 Jun 1992 15:30:18


        ...
:>I have written a text editor.
:>I am looking for a reliable way to differentiate between a single
:>Esc Keystroke and an Escape sequence generated by a special key (arrow
:>function key etc...).

No 100% reliable way.  The network or whatever is between your keyboard
and your program can introduce arbitrary delays - sooner or later you
WILL be unlucky, and the first byte of the escape sequence WILL be
followed by a *substantial* delay before the rest of the escape
sequence.

:>There must be a better way to do this, because vi has no problem.

If you work at it long enough, and with a suitably loaded and
unpredictable network, you WILL see problems with vi - lean on an
autorepeating arrowkey and sooner or later one of the "arrow"
keystrokes WILL get interpreted as a sequence of commands, dirtying
the file you're editing.

:>Any clue!

I would advise not to use the ESC key in the editor.  Much as it pains
me to admit that, DEC may have the right idea in hiding the key which
sends a single ESC code in strange places such as F11...

If you don't want to follow this advice, check if you can avoid having
the terminal generate the ESC code for function and arrow keys.  DEC
terminals, I believe, have an "8-bit-controls" mode in which special
keys send a single 8th-bit-high code to identify themselves, in place
of the usual ESC-]; check if the terminals you use have this
capability, if you can put them into this working mode, and put your
connection to the terminal in such a state that it will pass on the
8-bit control symbol cleanly...
--


 
 
 

1. Suse 7.2 ESC-ESC for commandoline fillout?

I have been using all kinds of Linux but it happens to be
that I like Suse Linux best. There is only one obstacle.
For commandoline fillout in a mixed UNIX environment
where other UNIX machines run the kornshell it is
natural to use ESC ESC (two times escape key).
In every other Linux there is no problems, but in
Suse Im forced to use the TAB key for commandoline
fillout when running the standard Bash shell.
Why have they disabled that Bash feature and how
can I get the thing working in normal order.

2. set defaults gives strange errors after applying 104288-07

3. Telnet from AIX 1.2 -> ESC key sends two ESC's

4. Email Accounts

5. Howto get TAB to do filename completion and not ESC ESC??

6. <where may i find a free NNTP server for Solaris 2.5.1

7. <ESC><ESC> or <TAB>

8. SB Live!

9. Help to change the Esc-Esc pattern matching functionality

10. Does Esc-Esc work on Solaris?

11. esc/esc -> TAB in ksh

12. Help to change the Esc-Esc pattern matching functionality

13. Meaning of ESC [ %d G and ESC [ %d d