Subject: Reading more than one key 82. ***** Q: How do I detect if more than one standard key is pressed down? A: The example code below relies very heavily on a Usenet posting by Lou Duchez ljduchez@en.com who wishes to acknowledge Bill Seiler for the handling of ports. The KeyNrDown and TEST routines are by myself. Besides being a demonstration the TEST procedure can be used to get the scan codes of the different keys instead of relying on external documentation. Uses Dos; {} var keydown: array[0..127] of boolean; { status array } oldkbdint: procedure; { points to the "normal" keyboard handler } port60h, port61h: byte; { used within the interrupt for storage } {} { The replacement keyboard handler } procedure newkbdint; interrupt; begin port60h := port[$60]; keydown[port60h and $7f] := (port60h <= $7f); port61h := port[$61]; port[$61] := port61h or $80; port[$61] := port61h; port[$20] := $20; end; {} { Get the scancode of the key pressed down, 128 for none } function KeyNrDown : byte; var i : byte; begin KeyNrDown := 128; for i := 0 to 127 do if KeyDown[i] then KeyNrDown := i; end; {} { Test by displaying the scan codes of the keys pressed } procedure TEST; var k, k1 : byte; begin k1 := 128; repeat k := KeyNrDown; if k <> k1 then begin write (k, ' '); if (k1 = 30) and (k = 31) then writeln ('Pressed A and S '); k1 := k; end; until k = $01; {escape} end; {test} {} begin { turn on the replacement keyboard handler } fillchar(keydown, 128, #0); { sets array to all "false" } getintvec($09, @oldkbdint); { record location of old keyboard int } setintvec($09, @newkbdint); { this line installs the new interrupt } {} TEST; {} { turn off the replacement keyboard handler } setintvec($09, @oldkbdint); end. --------------------------------------------------------------------