home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20160 < prev    next >
Encoding:
Text File  |  1993-01-25  |  1.4 KB  |  47 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!cs.utexas.edu!convex!egsner!adaptex!sdf!mkhan
  3. From: mkhan@sdf.lonestar.org (Muhammad Khan)
  4. Subject: Re: Telling if the SHIFT key is down.
  5. Message-ID: <C1CLpG.2HL@sdf.lonestar.org>
  6. Organization: sdf public access Unix, Dallas -- 214-436-3281
  7. References: <00966E8E.9CED30C0@Msu.oscs.montana.edu>
  8. Date: Sun, 24 Jan 1993 07:48:52 GMT
  9. Lines: 36
  10.  
  11.  
  12. he he he....
  13. This was one of my surprises when I played a pinball game on a PC.
  14. Hitting the left SHIFT would move the left bat and right SHIFT the
  15. right bat.  Actually PC BIOS gives this info.  Interrupt 16, service
  16. 2.  Following is a short program to detect left/right shift key presses.
  17. This is for Microsoft C, find appropriate subst. for _REGS, _int86 in
  18. Borland.
  19.  
  20. #include <stdio.h>
  21. #include <dos.h>
  22.  
  23. main()
  24. {
  25.      union _REGS inregs, outregs;
  26.      char LEFT_SHIFT=2, RIGHT_SHIFT=1;
  27.  
  28.      while (1) {    //infinite loop, change this as you like
  29.     inregs.h.ah=2;                 //request shift status
  30.     _int86(0x16, &inregs, &outregs);     //BIOS service 16H
  31.  
  32.     if (outregs.h.al & LEFT_SHIFT)         //left shift pressed
  33.          printf("Left shift pressed.\n");
  34.     else if (outregs.h.al & RIGHT_SHIFT) //right shift pressed
  35.          printf("Right shift pressed.\n");
  36.  
  37.      }
  38.  
  39.  
  40. }
  41.  
  42. ===========================================================================
  43. signed amjad;
  44. Muhammad Amjad Khan
  45. mkhan@sdf.lonestar.org
  46.  
  47.