home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / newemacs / getkey.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-01  |  2.3 KB  |  85 lines

  1. #include "ed.h"
  2.  
  3. /* This routine gets a key from the keyboard. It is written to take 
  4.  * advantage of the capabilities of an IBM PC keyboard. This routine 
  5.  * recognizes the arrow keys and the Ins and the Del and will not insert
  6.  * "garbage" characters for any recognizable key on the IBM PC keyboard.
  7.  */
  8.  
  9. getkey()
  10.     {
  11.     register int c; /* keycode for key pressed by user */
  12.     
  13.     /* get keycode */
  14.     c = get_keycode();
  15.     /* if META char (ESC) was pressed */
  16.     if (c == METACH) 
  17.         {
  18.         /* get 2nd character from the keyboard  */
  19.         c = get_keycode();
  20.         /* if char is lower case alpha */
  21.         if(c >= 'a' && c <= 'z') 
  22.             /* force it to upper case */
  23.             c -= 0x20;
  24.         /* if 2nd character is control character then */
  25.         if (c >= 0x00 && c <= 0x1f)
  26.             /* append control code to key stroke */
  27.             c = CTRL | ( c + '@');
  28.         /* append META code and return to caller */
  29.         return (META | c);
  30.         }
  31.     if ( c == CTRLCH ) /* apply C prefix */
  32.         {
  33.         c = getctl();
  34.         return(CTRL | c);
  35.         }
  36.     if (c == CTMECH) /* apply C-M-prefix */
  37.         {
  38.         getctl();
  39.         return(CTRL | META | c);
  40.         }
  41.     /* if control char then applay CTRL prefix */
  42.     if (c >= 0x00 && c <= 0x1f) 
  43.         c = CTRL | (c + '@');
  44.     }
  45.  
  46.  
  47. /*
  48.  * Get a key.
  49.  * Apply control modifications
  50.  * to the read key.
  51.  */
  52. getctl()
  53. {
  54.     register int    c;
  55.  
  56.     c = scr_ci();
  57.     if (c>='a' && c<='z')            /* Force to upper    */
  58.         c -= 0x20;
  59.     if (c>=0x00 && c<=0x1F)            /* C0 control -> C-    */
  60.         c = CTRL | (c+'@');
  61.     return (c);
  62. }
  63.  
  64. /* get keystroke from keyboard. This routine returns the ASCII code of the
  65.  * key that was pressed if the key pressed was an ascii character or a code
  66.  * that corresponds to the extended keycode if an extended keycode was pressed.
  67.  */
  68. int get_keycode() 
  69.     {
  70.     int c; /* keystroke returned from buffer */
  71.     char get_key();
  72.     char cc; /* ascii keystroke or 0 if extended keycode */
  73.     
  74.     /* get keycode from keyboard */
  75.     cc = get_key(&c);
  76.     /* if extended keycode then */
  77.     if (cc=='\0')
  78.         /* return special code that corresponds to extended keycode */
  79.         return(EXTKY | (c>>8));
  80.     else
  81.         /* return ascii code */
  82.         return (cc);
  83.     }
  84.  
  85.