# WAITKEY

Syntax:

Then: a = WAITKEY Wait for next keystroke. Used on "then" lines.
If: WAITKEY = "k" Same as above, but used on "if" lines.

Version Ref: 3.x

Description:

Waits for the next keystroke.

Examples:

WAITKEY used on the "then line:

WAITKEY stores the next key pressed in the prescribed dummy variable. You can test this variable and act accordingly upon its being one value or another. If you want to intercept Special Keys (from the Key Label list) you must designate a dummy variable of at least 4 characters in length, and an edit type capable of storing text.

wtcode If:
Then: a(4)=waitkey
If: a eq "Z"
Then: show "@The user pressed a Z" ; goto doZ
If: a eq "Y"
Then: show "@The user pressed a Y" ; goto doY
If: a eq "SAVE"
Then: show "@The user pressed ESCAPE." ; ESCAPE
If: a eq "CRUP"
Then: show "@The user pressed the UParrow";pushkey "[CRUP]";end
Then: goto wtcode

The code above shows how WAITKEY functions. If the user does not press any of "Z", "Y", "SAVE" or "CRUP" it will keep waiting until one of these keys is pressed. This is a powerful mechanism for forcing the user to press only those keys you want pressed.

WAITKEY use on the "if" line:

On the "if" lines, WAITKEY allows you to wait for particular characters and act upon receiving them from the user.

If: waitkey="z"
Then: show "@The user pressed a Z" ; end
Then: show "@The user pressed something other than a Z" ; end

Capturing special keys

If waitkey contains a null value, the key pressed was a special key, not a character key, and will be contained in the system-maintained field for special keys, @SK. The value will be a four-letter code from the Special Key Codes.

Here is an example in which the nature of the key captured, character or special, determines which routine is called, "gotchar" or "gotspec":

Then: aa=waitkey

If: aa ne ""

Then: goto gotchar

If: @sk="CDWN"

Then: goto gotspec

IMPORTANT: WAITKEY cannot detect or respond to the BREAK key.