Board index » delphi » keyboard-input

keyboard-input

Dear people

My question is: how can I read more than 1 key from the keyboard at  the same time?
For example: when you press two keys at the same time I want to know which.
I've heard it's "something with interrupt 16h" and a "keyboardbuffer", but i've never found any further explanation.

So, pleeeaaase help me.

email: diesv...@wins.uva.nl

 

Re:keyboard-input


Quote
Wouter Diesveld wrote:

> Dear people

> My question is: how can I read more than 1 key from the keyboard at  the same time?
> For example: when you press two keys at the same time I want to know which.
> I've heard it's "something with interrupt 16h" and a "keyboardbuffer", but i've never found any further explanation.

> So, pleeeaaase help me.

> email: diesv...@wins.uva.nl

Hey...

What you need is an interupt routine that traps the keyboard scan
codes.  The scan codes differ from ASCII in that there is a specific
number for each time a key is press and each time a key is released.  In
other words, hitting the letter "a" will generate a scan code and
releasing the "a" button will generate another one.  All you have to do
is keep track of which keys are down and which are up in an array.  Here
is some code that I wrote in BTP 7.0...Hope it helps. I hacked it out of
my code, so I also hope it runs :).

***************************************

Program Keyboard;

Uses crt,dos;

Const KEYBOARDINTR = 9;
      KEYBOARDPORT = $60;

{$F+}
procedure KeyboardHandler(Flags, CS, IP, AX, BX, CX, DX,
                          SI, DI, DS, ES, BP: Word);interrupt;
  var
    key : byte;
  Begin
    key := Port[KEYBOARDPORT];
    If key=72  then up   :=True;
    If key=200 then up   :=False;
    If key=75  then Left :=True;
    If key=203 then Left :=False;
    If key=77  then Right:=True;
    If key=205 then Right:=False;
    If key=80  then Down :=True;
    If key=208 then Down :=False;
    If key=57  then space:=True;
    If key=185 then space:=False;
    If CallBIOSHandler then
       Begin
         asm pushf end;
         BIOSKeyboardHandler;
       End
    else
       Port[$20] := $20;
  end;
{$F-}

Begin;
  GetIntVec(KEYBOARDINTR, @BIOSKeyboardHandler);
  SetIntVec(KEYBOARDINTR, Addr(KeyboardHandler));

  {Do stuff in here}

  SetIntVec(KEYBOARDINTR, @BIOSKeyboardHandler);
End.
*****************************

Other Threads