home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / actlib12.zip / TOOLS.ZIP / UNGETKEY.C < prev    next >
C/C++ Source or Header  |  1993-02-25  |  1KB  |  57 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #include "tools.h"
  4. #include <dos.h>
  5.  
  6.  
  7. /***
  8.  *
  9.  *  Function   :    ungetkey
  10.  *
  11.  *  Topics     :    Puts a 2-bytes key into the keyboard buffer
  12.  *                  (extended characters are added to 256).
  13.  *
  14.  *  Parameters :    in    int key           key to be buffered
  15.  *
  16.  ***/
  17.  
  18. void ungetkey( int key )
  19.  
  20. { unsigned far *kbuf = MK_FP( 0x40, 0x1C );  /* end of keyboard buffer */
  21.  
  22.   if ( key < 256 )       /*  normal ASCII character  */
  23.      {
  24.        *(unsigned char *)(MK_FP(0x40, *kbuf) ) = (unsigned char) key;
  25.        *(unsigned char *)(MK_FP(0x40, 1 + *kbuf) ) = 0;
  26.      }
  27.   else {                 /*  extended codes: 256 + key  */
  28.  
  29.          *(unsigned char *)(MK_FP(0x40, *kbuf) ) = 0;
  30.          *(unsigned char *)(MK_FP(0x40, 1 + *kbuf) ) = (unsigned char) (key - 256);
  31.        }
  32.  
  33.   if ( *kbuf == 0x3C ) *kbuf = 0x1E;
  34.                   else (*kbuf) += 2;
  35. }
  36.  
  37.  
  38. /*
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <conio.h>
  42.  
  43.  
  44. void main()
  45. {int r, key = 256 + 60;
  46.  
  47. ungetkey( key );
  48. ungetkey( 20 );
  49. ungetkey( 40 );
  50.  
  51. r = -1;
  52. if ( kbhit() ) r = getch();
  53. if ( ! r ) r = getch();
  54.  
  55. printf( "r = %d\n", r );
  56. }
  57. */