EKEY part 2 of 3 
Author Message
 EKEY part 2 of 3

EKEY Implementor's Notes                        Part 2 of 3

        : KEY?  ( -- flag )

           BEGIN  EKEY?  WHILE
              EKEY DUP 256 <  IF  PENDING-CHAR !  TRUE EXIT  THEN
        : KEY  ( -- char )

           BEGIN  EKEY  DUP 256 >=  WHILE  DROP  REPEAT

This is a full-featured implementation, providing the
application program with an easy way to either handle
non-character events (with EKEY), or to ignore them and to
only consider "real" characters (with KEY).

Note that EKEY maps scan codes from 0 to 255 into numbers from 256
to 511.  EKEY maps the sequence 0,3, representing the keyboard

0 (ASCII NUL).  Many ASCII keyboards generate ASCII NUL for

otherwise unavailable from MS-DOS, because the zero byte signifies
that another scan-code byte follows).

One consequence of using the "Direct STDIN Input" system call
(function 7) instead of the "STDIN Input" system call (function 8)
is that the normal DOS "Ctrl-C interrupt" behavior is disabled when
the system is waiting for input (Ctrl-C would still cause an
interrupt while characters are being output).  On the other hand, if
the "STDIN Input" system call (function 8) were used to implement

also cause an interrupt, because the operating system would
interpret the second byte of the 0,3 sequence as a Ctrl-C, even
though the 3 is really a scan code and not a character.  One "best
of both worlds" solution is to use function 8 for the first byte
received by EKEY, and function 7 for the scan code byte.  For

        : EKEY  ( -- u )
           DOS-KEY-FUNCTION-8  ?DUP  0=  IF
              DUP 3  =  IF  DROP 0  ELSE  256 +  THEN

Of course, if the Forth implementor chooses to pass Ctrl-C through
to the program, without using it for its usual interrupt function,
then DOS function 7 is appropriate in both cases (and some
additional care must be taken to prevent a typed-ahead Ctrl-C from
interrupting the Forth system during output operations).

A Forth system might also choose a simpler implementation of KEY ,
without implementing EKEY , as follows:

        : KEY   ( -- char )  DOS-KEY  ;
        : KEY?  ( -- flag )  DOS-KEY? 0<>  ;

Fri, 07 Jan 1994 21:58:25 GMT  
 [ 1 post ] 

 Relevant Pages 

1. EKEY part 3 of 3

2. EKEY part 1 of 3



5. EKEY in gforth in DOS

6. EKEY in gforth for linux?

7. KEY and EKEY

8. EKEY>CHAR in Win32Forth

9. portable definitions for KEY and EKEY?

10. EKEY and double numbers

11. KEY and EKEY

12. Key and EKey


Powered by phpBB® Forum Software