how do I trap a single keystroke in VMS C?

rankin at eql.caltech.edu rankin at eql.caltech.edu
Thu Jul 26 13:17:34 AEST 1990


In article <1990Jul25.085526.1 at vaxr.llnl.gov>, andersen at vaxr.llnl.gov writes:
> Does anybody have code written to trap a single keystroke in VMS C?  I know I
> need to use a QIO, and with enough dinking I could figure it out, but if I
> can steal somebody elses solution I'd much rather.  I need my code to respond
> to a keystroke without having to also hit RETURN.  (In OS-9 C, a 
> read( 0, &ch, 1) does the trick, but not in VMS.)

     This isn't really a C question; you'd get more of a response from
comp.os.vms.  $QIO is not difficult to use, but if you want to take the
simplest route, use SMG$READ_KEYSTROKE.  It handles the $QIO details and
also performs multi-byte escape sequence recognition (into an unsigned
short) for arrow and function keys.

#include <smgdef.h>	/* extended key codes */
 unsigned long kb, sts;
 unsigned short keycode;

 (void)SMG$CREATE_VIRTUAL_KEYBOARD(&kd);
 sts = SMG$READ_KEYSTROKE(&kd, &keycode);

Normal keys result in that key's ascii value being placed into 'keycode'.
Some control keys trigger out-of-band actions.  You'll need to either
use $QIO directly or place the terminal in VMS's equivalent of "raw" mode
if you want full control of those.

		Pat Rankin, rankin at eql.caltech.edu



More information about the Comp.lang.c mailing list