ascii or scancodes?
ih8mj at fjf.gnu.de
Fri May 29 20:44:07 CEST 2009
Martin Kalbfuß wrote:
> I have another problem with my text snake game. It's about the use of
> the keyboard functions of Crt.
> The player record has some fields holding the keys for changing the
> direction of the snake.
> I want the following key sets as standard.
> player 1:
> left -> a
> right -> d
> up -> w
> down -> s
> player 2:
> left -> arrow left
> right -> arrow right
> up -> arrow up
> down -> arrow down
> I found the scancodes for the arrow keys on the net, and they are
> working. But the scancodes I found for the letters doesn't. I also read
> that usb keyboards have different scancodes.
> Is it possible to use scancodes platform independent?
The CRT unit tries to be as BP compatible as possible, so it does
the same as BP does: For normal keys it returns the ASCII code, for
function keys it returns Chr (0) followed by the scan code.
On non-Dos platforms, it maps the keys to the Dos scancodes, so
they're quite platform independent.
BTW, the scan codes are defined in crt.inc (which is automatically
included in the CRT unit), e.g. ksLeft for the left key. (Note that
not all keys and combinations may be available on all platforms, but
the common keys such as left/right/up/down should be available on
any non-stoneage keyboard. ;-)
BTW^2, since the Chr (0) / scancode sequence is often a bit clumsy
to handle (you cannot just ignore the Chr (0), as many scancodes
overlap with regular ASCII characters), GPC's CRT unit provides as
an extension the function ReadKeyWord which returns an integer: for
normal keys the ordinal value of the ASCII code (0 .. 255), for
function keys 256 times the scancode. These codes are also defined
in crt.inc, e.g. kbLeft.
Frank Heckenbach, f.heckenbach at fh-soft.de, http://fjf.gnu.de/, 7977168E
GPC To-Do list, latest features, fixed bugs:
GPC download signing key: ACB3 79B2 7EB2 B7A7 EFDE D101 CD02 4C9D 0FE0 E5E8
More information about the Gpc