Depending on the emulator, you need to be wary of multi-byte keycodes which are 
used for function keys and such.

These multi-byte keycodes will begin with either CHAR(2) or CHAR(27) (for 
example), but can be followed by what are otherwise printable characters. If 
you do not filter them, you will get garbage in your input string if a user 
presses one of those keys.

Here is a routine I use (UV with wIntegrate):
=======================
KEY.BUFR = ''
LOOP
  INPUTIF JUNK, -1 THEN
    KEYCODE = SEQ(KEYIN())
    *
    * Check for multi-byte keycodes, such as from function keys, etc.
    * In wIntegrate, multi-byte keycodes begin with 2 or 27 and can be
    * anywhere from 2 to 5 bytes long. Enter sub loop to gobble up all
    * of the bytes. Also, special-case the ENTER key to get an immediate escape.
    IF KEYCODE EQ 2 OR KEYCODE EQ 10 OR KEYCODE EQ 27 THEN
      KEYSEQ = KEYCODE
      LOOP
        INPUTIF JUNK, -1: ELSE EXIT
        KEYSEQ := SEQ(KEYIN())
      REPEAT
      * If it is ENTER, then exit.
      IF KEYSEQ EQ 10 THEN EXIT
    END ELSE
      * Determine if this is a printable character, and if so, 
      * add it to the prompt buffer, increment the buffer count
      * and exit if we have chars.
      IF BITXOR(128,BITAND(255,KEYCODE + 1)) GT 160 THEN
        THIS.CHAR = CHAR(KEYCODE)
        PRINT '*':
        KEY.BUFR := THIS.CHAR
      END ELSE
        * Otherwise, ignore the key, unless it is a BACKSPACE.
        IF KEYCODE EQ 8 THEN
          PRINT CHAR(8):' ':CHAR(8):
          KEY.BUFR = KEY.BUFR[1, LEN(KEY.BUFR) -1]
        END
      END
    END
  END
  * Be sure to yield to the system.
  NAP 16
REPEAT
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to