KEYCODE()

Top  Previous  Next

 

The KEYCODE() function reads a single keystroke from the keyboard.

 

 

Format

 

KEYCODE({timeout})

 

 

The KEYCODE() function pauses program execution until a key is pressed. The character associated with that key is returned as the value of the function. The character is not echoed to the display.

 

KEYCODE() does not take data from the DATA statement queue.

 

The optional timeout parameter specifies a period in seconds after which the function will return if no input is received. In this case the returned value is a null string and the STATUS() function will return ER$TIMEOUT.

 

A null string is also returned when taking input from a pipe if the piped data stream is exhausted. In this case the STATUS() function will return ER$EOF. The value returned by the STATUS() function is not significant unless KEYCODE() has returned a null string.

 

The KEYCODE() function differs from KEYIN() in that it uses the terminfo database to identify certain special keys and returns the character representing the internal representation of that key as defined in the KEYIN.H include record in the SYSCOM file. The special keys recognised by this function are:

Function keys F1 to F12

Left, right, up and down cursor keys

Page up and Page down keys

Home and End

Insert and Delete

Backtab

Mouse

 

Use of the Escape key will return char(27) if no further characters are received within 200mS. This mechanism can be disabled using the BINDKEY() function.

 

 

Mouse Input on AccuTerm

 

The mouse code is returned when the mouse control prefix sequence defined in the terminfo database is detected. The way in which mouse clicks are handled varies considerably between different terminal emulators and will almost certainly require device specific programming. The following code sample works for the AccuTerm emulator in its vt100 mode if the terminfo kmous key is defined as "\E[101~".

 

C = KEYCODE()

IF SEQ(C) = K$MOUSE THEN

  S = ''

  LOOP

     C = KEYIN()

  UNTIL C = 'R'

     S := C

  REPEAT

  ROW = MATCHFIELD(S, '0X0N;0N', 2)

  COL = MATCHFIELD(S, '0X0N;0N', 4)

END

 

The above program fragment is for QM version 2.1-0 upwards as earlier versions used a different terminfo entry. Note that AccuTerm numbers rows and columns from one.

 

 

Stylus Input on a PDA

 

Stylus taps are enabled on a PDA using the @(IT$STYLUS) function. When enabled, a stylus tap sends char(200) (K$MOUSE) followed by the column and row coordinates, separated by a comma and terminated by a carriage return. The following function extends KEYCODE to recognise stylus taps, returning the mouse code to the caller and leaving the screen coordinates in a common block.

 

FUNCTION KEY()

  $CATALOGUE KEY

 

  $INCLUDE KEYS.H

  $INCLUDE KEYIN.H

 

  COMMON /STYLUS/STYLUS.ROW, STYLUS.COL

 

  DISPLAY @(IT$STYLUS,1):

  K = KEYCODE()

  DISPLAY @(IT$STYLUS,0):

  IF SEQ(K) = K$MOUSE THEN

     ECHO OFF

     INPUT S          ;* Get coordinate data

     HUSH OFF

     STYLUS.COL = MATCHFIELD(S, '0N","0N', 1)

     STYLUS.ROW = MATCHFIELD(S, '0N","0N', 3)

  END

 

  RETURN K

END