home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / getkeyc / getkey.c
Encoding:
Text File  |  1994-06-15  |  942 b   |  29 lines

  1. /*
  2.  *                 GetKey () is yet another replacement for getch ().
  3.  *                    This is about a quick and dirty as it gets.
  4.  *
  5.  *  If no character is waiting GetKey () returns 0.
  6.  *  If an ASCII character is waiting it returns the ASCII value and removes
  7.  *     the keystroke from the keyboard buffer
  8.  *  If it's an extended code it converts the code to a negative IE: F1 = -59
  9.  *     and returns the negative value.  The keystroke is remove from the
  10.  *     keyboard buffer.
  11.  *
  12.  *     (GetKey () == 0)     The no keystrokes waiting
  13.  *     (GetKey () <  0)     An extended code was converted to a
  14.  *                          negative and returned
  15.  *     (GetKey () >  0)     The ASCII code was returned.
  16.  */
  17.  
  18. int GetKey (void);
  19.  
  20. int GetKey (void)
  21. {
  22.     int iRetKeyVal;
  23.     if (!kbhit ())
  24.     {
  25.         return 0x00;
  26.     }
  27.     return (((iRetKeyVal = getch ()) != 0x00) ? iRetKeyVal : getch () * -1);
  28. }
  29.