Q: How can I detect if the shift/ctrl/alt etc key is pressed? I
know how to get the scan codes with the ReadKey function, but I
can't find the procedure for detecting these keys.
A: Detecting pressing the special keys or getting the toggle status
cannot be done with ReadKey. You'll need to access the Keyboard
Flags Byte at $0040:$0017. You can do this either by a direct "Mem"
access, or using interrupt $16 function $02. For more details
including the bitfields for the shift flags see in Ralf Brown's
interrupt list
ftp://garbo.uwasa.fi/pc/programming/inter61a.zip (or
whatever is the current version). For example to see if the alt key
is pressed you can use
uses Dos;
function ALTDOWN : boolean;
var regs : registers;
begin
FillChar (regs, SizeOf(regs), 0);
regs.ah := $02;
Intr ($16, regs);
altdown := (regs.al and $08) = $08;
end;
For the enhanced keyboard flags see interrupt $16 function $12. It
can distinguish also between the right and the left alt and ctrl
keys.
A tip from Martijn Leisink. Be careful [if you use the
$0040:$0017 memory position to set a toggle]: On several computers
you have to call int 16h after the new setting is shown by the LED's
on the keyboard. Not doing so might give the user wrong information.
Horst Kraemer adds: This is not true merely for several computers
but for _every_ computer.
A tip from Dr John Stockton. Going via a BytePointer set to
Ptr(Seg0040, $0017) is almost as easy as "Mem", and also works in
Protected mode (for TP version 7.0).
...