home *** CD-ROM | disk | FTP | other *** search
- #include "ed.h"
-
- /* This routine gets a key from the keyboard. It is written to take
- * advantage of the capabilities of an IBM PC keyboard. This routine
- * recognizes the arrow keys and the Ins and the Del and will not insert
- * "garbage" characters for any recognizable key on the IBM PC keyboard.
- */
-
- getkey()
- {
- register int c; /* keycode for key pressed by user */
-
- /* get keycode */
- c = get_keycode();
- /* if META char (ESC) was pressed */
- if (c == METACH)
- {
- /* get 2nd character from the keyboard */
- c = get_keycode();
- /* if char is lower case alpha */
- if(c >= 'a' && c <= 'z')
- /* force it to upper case */
- c -= 0x20;
- /* if 2nd character is control character then */
- if (c >= 0x00 && c <= 0x1f)
- /* append control code to key stroke */
- c = CTRL | ( c + '@');
- /* append META code and return to caller */
- return (META | c);
- }
- if ( c == CTRLCH ) /* apply C prefix */
- {
- c = getctl();
- return(CTRL | c);
- }
- if (c == CTMECH) /* apply C-M-prefix */
- {
- getctl();
- return(CTRL | META | c);
- }
- /* if control char then applay CTRL prefix */
- if (c >= 0x00 && c <= 0x1f)
- c = CTRL | (c + '@');
- }
-
-
- /*
- * Get a key.
- * Apply control modifications
- * to the read key.
- */
- getctl()
- {
- register int c;
-
- c = scr_ci();
- if (c>='a' && c<='z') /* Force to upper */
- c -= 0x20;
- if (c>=0x00 && c<=0x1F) /* C0 control -> C- */
- c = CTRL | (c+'@');
- return (c);
- }
-
- /* get keystroke from keyboard. This routine returns the ASCII code of the
- * key that was pressed if the key pressed was an ascii character or a code
- * that corresponds to the extended keycode if an extended keycode was pressed.
- */
- int get_keycode()
- {
- int c; /* keystroke returned from buffer */
- char get_key();
- char cc; /* ascii keystroke or 0 if extended keycode */
-
- /* get keycode from keyboard */
- cc = get_key(&c);
- /* if extended keycode then */
- if (cc=='\0')
- /* return special code that corresponds to extended keycode */
- return(EXTKY | (c>>8));
- else
- /* return ascii code */
- return (cc);
- }
-
-