Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a better way to use keyboard input?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
i am trying to write a game in which the character wanders around a map, killing fiends, finding items, and such. (ever play zelda for the NES?)
anyway, my problem is this: if you hold down the arrow key, it just keeps filling the keyboard buffer untill my comp starts beeping at me, and then continues the walking animation for some time after letting go. i am handling keyboard input as follows:

kb:
do: k$ = inkey$
loop while k$ = ""
select case k$
case chr$(0) + "H": gosub mvup ' *up*
case chr$(0) + "P": gosub mvdn ' *down*
case chr$(0) + "K": gosub mvlt ' *left*
case chr$(0) + "M": gosub mvrt ' *right*
case chr$(27): end
end select
goto kb

is there a way to clear the kb buffer? or even a better way to read the kb?
i have heard about people using peek to scan the kb, but i dunno where to peek.
also, i tried the "on key(n%) gosub label" command, but couldn't get the arrow keys to work. :(
any help or advice would be super appreciated.

 
I think this will clear the buffer and return only the first of a long string of key presses:
[tt]
GoodKeys$ = ""
DO
I$ = INKEY$
GoodKeys$ = GoodKeys$ + I$
IF I$ = "" THEN EXIT DO
LOOP
IF LEN(GoodKeys$) > 0 THEN I$ = LEFT$(GoodKeys$, 1)
[/tt]
Use I$ to represent the valid key press.

Hmmm... this might be a little tricky.

If it doesn't work I believe there is an interrupt to clear the buffer.
VCA.gif

Alt255@Vorpalcom.Intranets.com

"If you can get people to ask the wrong questions, they'll never find the right answers."[tt]
Thomas Pynchon[/tt]

Perhaps the reverse is also true....
 
Here's the loop that I would code:

[tt]
DO
DO

k$ = INKEY$
LOOP UNTIL LEN
(k$)
SELECT CASE k$
CASE CHR$(0) + "H":
'handle Up key
CASE CHR$(0) + "P":
'handle Down key
CASE CHR$(0) + "K":
'handle Left key
CASE CHR$(0) + "M":
'handle Right key
CASE CHR$(27):
'handle Esc key
quit% = -1
END SELECT
WHILE INKEY$
<> &quot;&quot;: WEND
LOOP UNTIL
quit%[/tt]

But then, I consider INKEY$ to be a deprecated method of keyboard input =} For realtime applications, I poll [tt]INP(&amp;H60)[/tt] (the hardware port of the keyboard) and update a table of keys that are currently pressed. I should write a FAQ on this :-D

*adds to list of FAQs to write*
 
Logiclrd, you are the man!

Please include options for using Interrupt &amp;H16, functions 01, 02, 05, 10, 11 and 12.

Looking forward to reading the FAQ.

BTW, you're quite right about INKEY$. Its functionality is limited.
VCA.gif

Alt255@Vorpalcom.Intranets.com

&quot;If you can get people to ask the wrong questions, they'll never find the right answers.&quot;[tt]
Thomas Pynchon[/tt]

Perhaps the reverse is also true....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top