home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / FGIN131.ZIP / SOURCE.ZIP / KEYCHECK.C < prev    next >
Text File  |  1994-01-21  |  1KB  |  56 lines

  1. /****************************************************************************\
  2.  
  3. \****************************************************************************/
  4.  
  5.  
  6. /****************************************************************************\
  7.  
  8.     int check_key(void)
  9.  
  10.             check_key() is my answer to a problem I got tired of encountering.
  11.         It checks to see if a key has been pressed, returning -1 if none, or
  12.         the extended key code (0x0159 for F1, 0x000D for CR, etc.) if one was
  13.         pressed.  The reason for this is that although getch() will get a key
  14.         without checking for ctrl-c or ctrl-break, it wait's for a key press.
  15.         On the other hand kbhit() doesn't get the waiting key, but it DOES
  16.         check for ctrl-c and ctrl-break.  DOS could use a couple more 0x21
  17.         interrupt functions.
  18.  
  19. \****************************************************************************/
  20. int check_key(void)
  21. {
  22.  
  23.     asm {
  24.  
  25.         mov ax,0x0600;    //Function 0x06
  26.         mov dx,0x00FF;    //Sub function 0xFF
  27.         int 0x21;        //Get a keypress IF there was one
  28.  
  29.         jnz Keypress;    //Jump if key was pressed
  30.  
  31.         mov ax,0xFFFF;
  32.         jmp End;            //Return -1 because no key was pressed
  33.  
  34.     }
  35.  
  36. Keypress:
  37.  
  38.     asm {
  39.  
  40.         and ax,0x00FF;    //Check status of al
  41.         jnz End;            //Key is not extended key return character
  42.  
  43.         mov ax,0x0700;    //Get extended character we know it's there
  44.         int 0x21;
  45.  
  46.         mov ah,0x01;    //Set high byte of AX to indicate extended key
  47.  
  48.     }
  49.  
  50. End:
  51.  
  52.     return(_AX);
  53.  
  54. }
  55.  
  56.