Page 1 of 1

Keyboard Help

Posted: Fri Feb 01, 2008 3:16 pm
by BluescreenODeff
Hi everyone; I don't usually post on this site, but it seems quite fascinating. Anywho, I have this code for a game I'm working on:

Code: Select all


a$ = INKEY$
IF a$ = "??" then (do this)
IF a$ = "??" then (do that)
IF a$ = "??" then (do this)

Anyway, It's all part of a loop. The problem is, is that I have that delay once I first press the button and hold it, then it goes without any delay until I release the button.

I've tried to use a command with hex code (I forgot what it was), and it worked, except that after a second or two of holding that key down, the computer beeps at me.

What do I need to do so I can press and hold a key; and for every loop in which the key is held, the "character" moves a step (and without beeps)? What I guess what I'm looking for is smooth character movement and not jagged. Thanks in advance and God Bless!

Posted: Fri Feb 01, 2008 4:40 pm
by Codemss
There is a function called MULTIKEY posted by BadMrBox, that is very food for this, you can download it here: http://www.qbasic.com/wbb/filebase_entr ... 56e2547d54

OR:
If you clear the keyboard buffer each frame with this:
DO UNTIL INKEY$ = ""
LOOP
a$ = ""

This may help for the beeping and makes it work better. You still have the problem that the program skips the inkey.

Posted: Fri Feb 01, 2008 10:36 pm
by BluescreenODeff
Hmm...the program you gave me returned an error "Duplicate Definition" within the Function.

Posted: Sat Feb 02, 2008 4:50 am
by Mac
BluescreenODeff wrote:Hmm...the program you gave me returned an error "Duplicate Definition" within the Function.
Dang! Don't you just hate posted code with bugs.

Maybe by insuring the function has % everywhere consistently. But there is no driver program, so it would be hard to understand or see if the function is useful with a lot of work.

Look instead at the demo I wrote
http://www.network54.com/Forum/171757/m ... 1042468970

It actually runs! Select the asterisk-moving demo and see if that works a bit according to your need. You can possibly see better if you modify A1.Demo: Replace the timer pause in subroutine "Move2" with
FOR i = 1 TO 9: WAIT &H3DA, 8: WAIT &H3DA, 8, 8: NEXT i

The overall problem is that if you just use INKEY$, you get this
- User presses a key and holds it down
- QBasic returns the key value
- QBasic stalls a long time to make sure you really want multi-returns
- Finally QBasic starts acting as if the user is pressing key quickly
- User releases key
- There are still keypresses in the buffer and so you wind up getting jerky movement plus movement after you wanted to stop.

You can avoid the extra keypresses by something like this:

Code: Select all

DO
  WHILE INKEY$ <> "": WEND
  k$ = INPUT$(1)
  PRINT ".";
LOOP WHILE k$ <> CHR$(27)' ESC key to stop
But the stall can't be avoided without something in assembler such as the demo I provided above.

Mac

Posted: Sat Feb 02, 2008 8:13 pm
by BluescreenODeff
It still doesn't work on mine.? Maybe I'm using a buggy version of QB.? I look in the Index, and it says that it has the CALL ABSOLUTE command there (with an example).? However, it returns a "Subprogram Not Defined" error, thinking that CALL ABSOLUTE is CALL (it returned an error in the example, too!)

Posted: Sat Feb 02, 2008 8:16 pm
by BluescreenODeff
Never mind! I see what the problem is. I forgot to put the "\l" there in the command line. Yes, your program works; Thanks and God Bless!