home *** CD-ROM | disk | FTP | other *** search
- \ Lesson 3 Part 7 ( F-PC 3.5 Tutorial by Jack Brown )
- COMMENT:
- Further discussion of the KEY_TEST program from Lesson 3 Part 5.
-
- New Word: KEY Wait for user to press key on keyboard and
- KEY ( -- n ) return the key code n. If n is < 128 then n
- is the ASCII code for the key pressed. If n
- is > 128 then n is the function key scan code
- + 128.
-
- Old Word: EXIT Stops compilation when not in a colon definition
- EXIT ( -- ) When compiled in a word, EXIT , will cause
- termination of word execution when encountered.
- COMMENT;
- : KEY_TEST ( -- )
- BEGIN CR KEY \ Wait for key press by user.
- DUP CONTROL M = \ Control M is return key.
- IF DROP EXIT THEN \ Exit infinite loop if pressed.
- DUP . EMIT \ Otherwise show key pressed.
- AGAIN ;
-
- COMMENT:
- Another version of KEY... or We don't always like F-PC's KEY so we
- made our own version of KEY that we call PCKEY .
-
- Here is our PCKEY definition. Our version returns a flag that can
- be immediately tested to determine whether an ASCII key was pressed
- (true flag returned) or a function key was pressed (false flag
- returned).
-
- Note: BIOSKEY ( -- n) Is a primitive keyboard input word that returns
- a 16-bit number whose high 8 bits consist of the keyboard scan code and
- whose low 8-bits consist of the ASCII code of the key pressed. If the
- key is not an ASCII key then the low 8-bits are zero.
- COMMENT;
-
- \ This is a different type of keyboard input routine.
- \ Return ASCII code and tf or function key scan code and ff.
- : PCKEY ( -- n flag )
- BIOSKEY DUP 127 AND \ Mask of low 8-bits to check for ASCII
- IF 127 AND TRUE \ Yes its ASCII, mask off ASCII value.
- ELSE FLIP FALSE \ Its a function key, leave scan code.
- THEN ;
-
-
- \ Test ascii keys and function keys.
- : PCKEY_TEST ( -- )
- BEGIN CR PCKEY
- IF DUP CONTROL M = \ Control M is return key.
- IF DROP EXIT THEN \ Exit infinite loop if pressed.
- ." ASCII key character code = "
- DUP . EMIT \ Display code and character.
- ELSE ." Function key scan code = " . \ Display scan code.
- THEN
- AGAIN ;
-
-