home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / pascal / 5167 < prev    next >
Encoding:
Text File  |  1992-09-01  |  1.8 KB  |  70 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!mcsun!sunic!lth.se!efd.lth.se!d92bo
  3. From: d92bo@efd.lth.se (Bengt Oehman)
  4. Subject: Re: Read any key from the keyboard?
  5. Message-ID: <1992Sep2.103138.11855@lth.se>
  6. Sender: newsuser@lth.se (LTH network news server)
  7. Reply-To: d92bo@efd.lth.se (Bengt Oehman)
  8. Organization: Lund Institute of Technology
  9. References:  <1992Sep1.123402.160@csghsg5a.bitnet>
  10. Date: Wed, 2 Sep 1992 10:31:38 GMT
  11. Lines: 57
  12.  
  13. Instead of using DOS calls to read the keyboard flags, you
  14. can read them directly in the BIOS data area (segment $0040).
  15.  
  16. The flags are at position $0040:$0017, and can be read directly with MEM.
  17.  
  18. Example:
  19.  
  20. CONST Num = $20;
  21.       Caps = $10;
  22.       LShift = $01;
  23.       RShift = $02;
  24.  
  25. VAR   KbdFlag = BYTE ABSOLUTE $0040:$0017;
  26.  
  27. BEGIN
  28.   IF (KbdFlag AND Num) = Num THEN Writeln('Num lock is active');
  29.   Write('Press left shift key: ');
  30.   REPEAT UNTIL (KbdFlag AND LeftShift)>0;
  31.   { Invert caps lock state }
  32.   KbdFlag:=(KbdFlag XOR Caps);
  33.   { this should get your caps diod to change }
  34. END.
  35.  
  36. The codes are by the way actually stored as a word, but in this case only the byte section is important.
  37.  
  38. I don't remember the exact codes of the keys, but if you write
  39. a simple test program you can find these out, You can for example
  40. test whether the NumLock key is pressed and inactive at the same time,
  41. or if scroll lock is active and pressed, or any such combination.
  42.  
  43. Example test program:
  44.  
  45. USES Crt;
  46.  
  47. VAR KbdFlag : Word ABSOLUTE $0040:$0017;
  48.     ch : char;
  49.  
  50. Procedure WriteWord(w : word);
  51. VAR i : integer;
  52. BEGIN
  53.   GotoXY(1,1);
  54.   FOR i:=15 DOWNTO 0 DO IF ((w SHR i) AND 1) >0 THEN Write('1') ELSE Write('0');
  55. END;
  56.  
  57. BEGIN
  58.   REPEAT 
  59.     WriteWord(KbdFlag);
  60.     IF KeyPressed THEN ch:=readkey;
  61.   UNTIL ch = chr(27); { escape }
  62. END.
  63.  
  64.  
  65. Hope this helped. It's fun, anyway.
  66.  
  67. /BEN d92
  68.  
  69. (d92bo@efd.lth.se)
  70.