Board index » delphi » help needed with keyboard routine

help needed with keyboard routine

Hi,

I'm writing a game for a school project, and so far have 1 problems. I
have written a sprite editor, and donw the code to load it in pascal, and
it works great, however, when moving it, I need to read a key from the
keyboard, and move it according to which key is pressed, and if the key is
held down, the sprite must keep moving in the desired direction. The
problem is, readkey is to damn slow. I have a while..keypressed statement,
but it doesn't seem to work. Here is basicly what I have at the moment :

repeat
  ch := readkey;
  if ch = #77 then
  while keypressed do
  Begin
    Putsprite ('car', X, Y);
    X := X + 1;
  End;
Until ch = #27;

 ...you get the idea

please help.

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet

 

Re:help needed with keyboard routine


I don't know if this will help you, but I try :
The bytesat mem[65:8] and mem[65:9] depend on wheter the Ctrl and Alt keys
are pressed. Their value changes immediatly and stays changed until you
release the key.
Normally the value of the both bytes is 0. Pressing these keys give changes
to mem[65:8]:
Right shift key : 1
Left shift key : 2
Ctrl : 4
Alt : 8
Pressing the left ctrl key sets mem[65:9] to 1 and pressing the left alt
key set this byte to 2.
By releasing any of these keys, the value is reset to 0. EXCEPT :
By pressing the following keys, the value an mem[65:8] is set until the key
is pressed again :
Scroll lock : 16
num lock : 32
Caps lock : 64
Insert : 128.

Pressing two keys at the same time, make the byte add up,
for instance : pressing ctrl-alt  makes the byte go 12.
If num-lock is on, pressing the right shift key makes the byte go 33 and so
on.
With someting like
if mem[65:8] and 4
  then
     ....
you could set some action for pressing the control key.

Carl

rog...@eastcoast.co.za wrote in article <867083398.24...@dejanews.com>...

Quote
> Hi,

> I'm writing a game for a school project, and so far have 1 problems. I
> have written a sprite editor, and donw the code to load it in pascal, and
> it works great, however, when moving it, I need to read a key from the
> keyboard, and move it according to which key is pressed, and if the key
is
> held down, the sprite must keep moving in the desired direction. The
> problem is, readkey is to damn slow. I have a while..keypressed
statement,
> but it doesn't seem to work. Here is basicly what I have at the moment :

> repeat
>   ch := readkey;
>   if ch = #77 then
>   while keypressed do
>   Begin
>     Putsprite ('car', X, Y);
>     X := X + 1;
>   End;
> Until ch = #27;

>  ...you get the idea

> please help.

> -------------------==== Posted via Deja News ====-----------------------
>       http://www.dejanews.com/     Search, Read, Post to Usenet

Other Threads