Keyboard Help

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
BluescreenODeff
Coder
Posts: 17
Joined: Sat Aug 11, 2007 10:35 am
Location: Kansas
Contact:

Keyboard Help

Post 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!
--Bluescreen O'Deff
John 1:1, John 3:16, Acts 10:38
User avatar
Codemss
Veteran
Posts: 124
Joined: Sun Jun 24, 2007 6:49 am
Location: Utrecht, The Netherlands
Contact:

Post 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.
Check out my site: <a href="http://members.lycos.nl/rubynl">Click here</a>
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL
User avatar
BluescreenODeff
Coder
Posts: 17
Joined: Sat Aug 11, 2007 10:35 am
Location: Kansas
Contact:

Post by BluescreenODeff »

Hmm...the program you gave me returned an error "Duplicate Definition" within the Function.
--Bluescreen O'Deff
John 1:1, John 3:16, Acts 10:38
Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

Post 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
User avatar
BluescreenODeff
Coder
Posts: 17
Joined: Sat Aug 11, 2007 10:35 am
Location: Kansas
Contact:

Post 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!)
--Bluescreen O'Deff
John 1:1, John 3:16, Acts 10:38
User avatar
BluescreenODeff
Coder
Posts: 17
Joined: Sat Aug 11, 2007 10:35 am
Location: Kansas
Contact:

Post 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!
--Bluescreen O'Deff
John 1:1, John 3:16, Acts 10:38
Post Reply