Board index » delphi » Keyboard Input

Keyboard Input

Hi,
My problem is this : I am writing a silly little demo in Pascal/Asm and
when ever i am tyring to get keyboard input, the animation slows down
badly...

Can someone help with information on how to program a real quick keyboard
handler routine ??

Thank you,
Rob

 

Re:Keyboard Input


Oops - kbstart = $1E;

Best Regards,

Mike Monett: ADDIDE, NoSpam, LP.EXE
http://www.csolve.net/~add/zips/addide.htm
ftp://www.headwaters.com/pub/add/zips/addide.htm

Re:Keyboard Input


Again Oops! Please change

            if ((cv >= A32) and (cv <= TilCh)) then

to
            if ((cv >= ' ') and (cv <= '~')) then

Sorry - I copied this from working code - hard to spot all the needed
variables and constants. Hope I got them all by now!

Best Regards,

Mike Monett: ADDIDE, NoSpam, LP.EXE
http://www.csolve.net/~add/zips/addide.htm
ftp://www.headwaters.com/pub/add/zips/addide.htm

Re:Keyboard Input


Quote
Rob Wright wrote:

> Hi,
> My problem is this : I am writing a silly little demo in Pascal/Asm and
> when ever i am tyring to get keyboard input, the animation slows down
> badly...

> Can someone help with information on how to program a real quick keyboard
> handler routine ??

> Thank you,
> Rob

I came across a very fast keyboard handler that I could not use because it did not allow
my programs to be used with TSR's. Maybe you could use it - I supplied an alternate
keyboard handler in case you need to check for TSR's.

Sorry for the long lines - I used the full window width in Netscape to avoid wrapping
the comments.

uses
  ZKeys;                                {keyboard constants}

  {http://www.csolve.net/~add/zips/zkeys.pas}

var                                     {Keyboard Variables}
  ch1        : char;                    {keeps case if char input}
  cv         : char;                    {input char upper-case}
  kbhead     : word absolute $40:$1a;   {points to head of keyboard buffer}
  kbtail     : word absolute $40:$1c;   {points to tail of keyboard buffer}
  khi        : byte;                    {high byte of keyboard memory}
  klo        : byte;                    {low byte of keyboard memory}
  wkey       : word;                    {complete keystroke}

function Keyhit: boolean; assembler;    {Not recommended: kills TSR's}

  asm                                   {very fast keyboard reader}
    cli                                 {useful inside fast loops when}
    push ds                             {interrupts must be turned off}
    mov ax, 40h
    mov ds, ax
    mov ax, [1ah]
    cmp ax, [1ch]
    mov ax, 0
    jz @nopress
    inc ax
    @nopress:
    pop ds
    sti
  end;

procedure ReadBuffer;

  begin
    inline($FA);
    klo := mem[$40:(kbhead)];           {read low byte of keystroke}

    khi := mem[$40:(kbhead + 1)];       {read high byte of keystroke}
    inline($FB);

    if (klo = $E0) then                 {kill Compaq keypad char}
    klo := 0;

    ch1  := chr(klo);                   {track case}
    cv   := upcase(chr(klo));           {low byte holds ASCII character}
    wkey := (khi shl 8) + klo;          {combine hi and low bytes}
  end;

procedure ClearKbd;

  begin
    inline($FA);                        {interrupts off when accessing memory}
    kbhead := kbstart;                  {reset keyboard pointers}
    kbtail := kbstart;
    inline($FB);
  end;

function GetKey : boolean;              {substitute if you use TSR's}

  begin                                 {all user interface start here}
    Getkey := false;                    {not true yet}

    if (KeyHit) then                    {use KeyPressed for TSR's}
    begin
      ReadBuffer;                       {get ch and Wkey}
      ClearKbd;                         {remove keystroke from kbd buffer}
      GetKey := true;                   {report key was pressed}
    end;
  end;

procedure MainLoop;

  begin
    InitStuff;                          {initialization and setup go here}

    repeat                              {main command loop}

      if (KeyHit) then                  {fast keyboard check}
      begin
        ReadBuffer;                     {get ch and Wkey}
        ClearKbd;                       {remove keystroke from kbd buffer}

        case wkey of                    {handle Function, Alt, Ctrl, cursor keys}

          EndKey : DoEndKey;
          Esc    : DoEscKey;
          Home   : DoHome;
          Left   : DoLeft;
          Left   : DoLeft;
          PgUp   : DoPageUp;
          Right  : DoRight;
          else
          if ((cv >= A32) and (cv <= TilCh)) then
          case cv of
            begin
              'Q' : DoQKey;
              'A' : DoAKey;
            end;
          end;
        end;
      end;
    until done;
  end;

Hope this helps.

Best Regards,

Mike Monett: ADDIDE, NoSpam, LP.EXE
http://www.csolve.net/~add/zips/addide.htm
ftp://www.headwaters.com/pub/add/zips/addide.htm

Re:Keyboard Input


Quote
"Rob Wright" <rwri...@es.co.nz> wrote:

//--Hi,
//--My problem is this : I am writing a silly little demo in Pascal/Asm and
//--when ever i am tyring to get keyboard input, the animation slows down
//--badly...
//--
//--Can someone help with information on how to program a real quick keyboard
//--handler routine ??

Have you got some source code examples?
Are you using int 16h? Or reading directly from the keyboard (port
60h)?

//--Thank you,
//--Rob

-------------------------------------------------------
 Ned...@WorldOnline.nl
 WWW: http://www.worldonline.nl/~nederm
 AKA Mighty Research
 Sig. version 1.05.934.352a  build 7831

Re:Keyboard Input


In article <337B68BB.5...@Today.Bud> of Thu, 15 May 1997 12:49:15 in
comp.lang.pascal.borland, Mike Monett <NoJunkEm...@Today.Bud> wrote:

Quote
>Again Oops! Please change
>            if ((cv >= A32) and (cv <= TilCh)) then
>to
>            if ((cv >= ' ') and (cv <= '~')) then

IIRC,   if cv in [A32..TilCh]   /   if cv in [' '..'~']   will generate
(possibly surprisingly) shorter code.

--
John Stockton, Surrey, UK.    j...@merlyn.demon.co.uk    Turnpike v1.12    MIME.
  Web URL: http://www.merlyn.demon.co.uk/ -- includes FAQqish topics and links.
  Correct 4-line sig separator is as above, a line comprising "-- " (SoRFC1036)
  Before a reply, quote with ">" / "> ", known to good news readers (SoRFC1036)

Other Threads