home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!mcsun!sunic!lth.se!efd.lth.se!d92bo
- From: d92bo@efd.lth.se (Bengt Oehman)
- Subject: Re: Read any key from the keyboard?
- Message-ID: <1992Sep2.103138.11855@lth.se>
- Sender: newsuser@lth.se (LTH network news server)
- Reply-To: d92bo@efd.lth.se (Bengt Oehman)
- Organization: Lund Institute of Technology
- References: <1992Sep1.123402.160@csghsg5a.bitnet>
- Date: Wed, 2 Sep 1992 10:31:38 GMT
- Lines: 57
-
- Instead of using DOS calls to read the keyboard flags, you
- can read them directly in the BIOS data area (segment $0040).
-
- The flags are at position $0040:$0017, and can be read directly with MEM.
-
- Example:
-
- CONST Num = $20;
- Caps = $10;
- LShift = $01;
- RShift = $02;
-
- VAR KbdFlag = BYTE ABSOLUTE $0040:$0017;
-
- BEGIN
- IF (KbdFlag AND Num) = Num THEN Writeln('Num lock is active');
- Write('Press left shift key: ');
- REPEAT UNTIL (KbdFlag AND LeftShift)>0;
- { Invert caps lock state }
- KbdFlag:=(KbdFlag XOR Caps);
- { this should get your caps diod to change }
- END.
-
- The codes are by the way actually stored as a word, but in this case only the byte section is important.
-
- I don't remember the exact codes of the keys, but if you write
- a simple test program you can find these out, You can for example
- test whether the NumLock key is pressed and inactive at the same time,
- or if scroll lock is active and pressed, or any such combination.
-
- Example test program:
-
- USES Crt;
-
- VAR KbdFlag : Word ABSOLUTE $0040:$0017;
- ch : char;
-
- Procedure WriteWord(w : word);
- VAR i : integer;
- BEGIN
- GotoXY(1,1);
- FOR i:=15 DOWNTO 0 DO IF ((w SHR i) AND 1) >0 THEN Write('1') ELSE Write('0');
- END;
-
- BEGIN
- REPEAT
- WriteWord(KbdFlag);
- IF KeyPressed THEN ch:=readkey;
- UNTIL ch = chr(27); { escape }
- END.
-
-
- Hope this helped. It's fun, anyway.
-
- /BEN d92
-
- (d92bo@efd.lth.se)
-