KeyScan routine

TURBU

KeyScan routine

 

Checks to see if any commands are being entered from the keyboard.

 

Syntax

 

function keyScan(mask: word; wait: boolean): byte;

 

Description

 

The keyScan routine checks to see if any command keys are being pressed.  This includes arrow keys as well as action buttons.  The mask parameter determines which keys are checked for, according to the predefined key constants.  If true is passed to wait, then the script will pause until the player presses a key, but if wait is false, it will scan the keyboard once and return a value based on whatever key is currently pressed.

 

Mask key constants:

NAME         VALUE

KS_DOWN: down arrow     1

KS_UP: up arrow       2

KS_LEFT: left arrow     4

KS_RIGHT: right arrow     8

KS_DIRS: any arrow key     0xF

KS_ACTION: action button (enter)   0x10

KS_CANCEL: cancel button (escape) 0x20

KS_ALL: all input keys.       0xFFFF

 

These names represent hexidecimal numbers, and can be combined with the word or.  For example, to check for either the action button or the cancel button, but not the arrow keys, you would pass "KS_ACTION or KS_CANCEL" to mask.  The KS_DIRS and KS_ALL variables include several numbers already combined, to simplify things.

 

Return values:

0: No key pressed.

1: Down arrow

2: Left arrow

3: Right arrow

4: Up arrow

5: Action button

6: Cancel button

 

NOTE:  If 0 is passed to mask, there will be nothing to scan for, and the routine will immediately return a value of 0, even if wait is true.  This is to avoid deadlocking the script in an infinite loop.

NOTE:  KS_ALL does not check for <SPACE>, which opens the console window instead of sending input to the game itself.

NOTE:  This routine automatically delays 10 miliseconds (1/100 of a second) before returning when wait is false.  This is necessary to avoid a timing issue that could stall the program if keyScan is used in a loop.  This is a very short delay and should not cause any problems, but any scripts that depend on very precise timing may need to take this delay into account.

This help file was created with the free trial version of HelpScribble.