key

Purpose

Returns the ASCII value of the next key available in the keyboard buffer.

Format

y = key()
Returns

y (scalar) – ASCII value of next available key in keyboard buffer.

Examples

format /rds 1,0;
kk = 0;

// Loop until q key
do until kk == 113;
   kk = key;
   if kk == 0;

      continue;

   elseif kk == vals(" ");

      print "space \\" kk;

   elseif kk >= vals("0") and kk <= vals("9");

      print "digit \\" kk chrs(kk);

   else;

      print "\\" kk;

   endif;
endo;

This is an example of a loop that processes keyboard input. This loop will continue until the q key (ASCII 113) is pressed.

Remarks

If you are working in terminal mode, key() does not “see” any keystrokes until ENTER is pressed. The value returned will be zero if no key is available in the buffer or it will equal the ASCII value of the key if one is available. The key is taken from the buffer at this time and the next call to key will return the next key.

Here are the values returned if the key pressed is not a standard ASCII character in the range of 1-255:

Value

Key Sequence

1015

Shift+Tab

1016-1025

Alt+Q, W, E, R, T, Y, U, I, O, P

1030-1038

Alt+A, S, D, F, G, H, J, K, L

1044-1050

Alt+Z, X, C, V, B, N, M

1059-1068

F1-F10

1071

HOME

1072

CURSOR UP

1073

PAGE UP

1075

CURSOR LEFT

1077

CURSOR RIGHT

1079

END

1080

CURSOR DOWN

1081

PAGE DOWN

1082

INSERT

1083

DELETE

1084-1093

Shift+F1-F10

1094-1103

Ctrl+F1-F10

1104-1113

Alt+F1-F10

1114

Ctrl+PRINT SCREEN

1115

Ctrl+CURSOR LEFT

1116

Ctrl+CURSOR RIGHT

1117

Ctrl+END

1118

Ctrl+PAGE DOWN

1119

Ctrl+HOME

1120-1131

Alt+1, 2, 3, 4, 5, 6, 7, 8, 9, 0, -, =

1132

Ctrl+PAGE UP

See also

Functions keyw(), vals(), chrs(), upper(), lower(), con(), cons()