3.03 Stream Input

Overview

Stream input is carried out using the GET Command.

GET

Function:

Reads a stream of data from the source and assigns the data under the control of the template.

Syntax:

GET [source,] [prompt,] template
Possible values for source are:
STDIN/SYSIN (default value)
CONSOLE
INKEY
DATA
STRING expression
FILE file
ERROR
prompt
A prompt string. This is written to the current output destination.
template
The parsing template.

Templates

A template contains rules for editing the input. Templates are described in 3.04 Input Templates.

String Input

The get command can be used to process a string expression.

get string "Extract word2 and word4", . w1 . w2
put w1 w2        // displays "word2 word4"

This can be used to assign a default value. in the following example the supplied value will be used if it contains anything, otherwise the default value will be used.

get string supplied 'default', result .

INKEY

Using the INKEY option, a single key press can be read from the computer keyboard.

The target is a single variable.

GET INKEY var

For alphanumeric keys the UTF-8(?) value of the key is returned. For control keys a value in the range 0xFF00-0xFFFF is returned.

INKEY

Function:

This function returns the last key-code in keyboard buffer, or an empty string if there are no keys.

Syntax:

INKEY

Special key-codes like the function-keys (PC) or the hardware-buttons (PalmOS) are returned as 2-byte string.

Example:

k = INKEY
IF LEN(k)
  IF LEN(k) = 2
    ? "H/W #"+ASC(RIGHT(k,1))
  ELSE
    ? k; " "; ASC(k)
  FI
ELSE
  ? "keyboard buffer is empty"
FI

lynplex/lp0303.txt · Last modified: 2011/11/06 10:16 by don