Read a key-event from the keyboard#

(Basic listing from Thomas E. Rowley - "Atari Basic spielend lernen")

How to use#

The Forth listing show two differnt way to read a keypress. The first one is the same technique used in the BASIC Program, the second is portable across many F83 Standard and ANSI Standard Forth versions.

Basic Version

10 REM READ A KEYPRESS
20 PRINT "PLEASE PRESS A KEY"
30 POKE 764,255
35 IF PEEK(764)=255 THEN 35
36 KEY=PEEK(764)
40 CLOSE #1:OPEN #1,4,0,"K:":GET #1,A
50 PRINT "THE KEYCODE OF"; CHR$(A); " IS "; KEY
60 GOTO 30

volksForth

: READKEY ( Read Keyboard direct from Shadow register )
  ." press a key" CR
  255 764 C!
  BEGIN
        764 C@
        255 < IF
           764 C@
           ." the keycode of " DUP EMIT ."  is " . CR
           255 764 C!
        THEN
  REPEAT ;

alternative version


: READKEY ( Read Keycode with Forth KEY Words )
  ." press a key" CR
  BEGIN
        KEY? IF
           KEY
           ." the keycode of "  DUP EMIT ." is "  . CR
        THEN
  REPEAT ;