Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
INKEY$
#1
Hey guys it is me again, I was just wondering if it was possible to make it so it did something to the affect of:

IF INKEY$ = "anykey" THEN GOTO 1

or something like that. I know that "anykey" is not a valid parameter for the INKEY statement, but, I was wondering if someone knew how to do it anyway. I know how to make it so that if you push q or enter then it goes to 1 but is there a way to make it so that if a user pushes any key on the entire keyboard that it will go? Any help would be appreciated

(it's probably in that manual, but whatever Wink )
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#2
*cries again*
[Image: bawling.gif]

IF INKEY$ <> "" THEN GOTO 1

That's ONE of the N^999 solutions to your question!





*looks hopeless to his shotgun*
img]http://usuarios.vtr.net/~disaster/sigs/annoyizer.php[/img]
Reply
#3
Yeah. That's how it works: INKEY$ is just like a string variable where the system puts a string which consists on the keys that are in the buffer. If no key has been pressed, the buffer is empty and INKEY$="". When a key is pressed, whatever the key is (except CTRL, SHIFT and such) copied in ascii form to the INKEY$ variable. That way, INKEY$=something or, what it's the same INKEY$<>"".

Anyways, it is better to clear the buffer before. Y'know, imagine a long loop in your program. If you press a key, as it is not being read, it will remain in a buffer. If you have an IF INKEY$<>"" THEN ... sentence right after the buffer, that key will be read by INKEY$ and maybe that's not what you like. So it is better to do this:

Code:
WHILE INKEY$<>"":WEND   ' loops while the buffer is full.
WHILE INKEY$="":WEND    ' waits for a new keypress.

Note the loops: The first one loops while there are keys pressed. That cleans the buffer. Then, the second one, loops while there aren't keys pressed, so it will exit when you press a key. Note that this is only aplicable when you are just waiting for a keypress, and not if you want that keypress to exit a loop, like for example in the challenge screensaver snippets, where you have to use HD's sollution.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#4
SOR-EE guys jeepurs at least Na_th_an was nice enough to give me a straight out answer and not cry about it.

No but seriously, Sorry for acting like a total newbie (with a swelled ego) because I THOUGHT I was a good programmer but I guess (after seeing you guys) I am really just a beginner (to intermediate) one.................. So, thanks be to you all ye programmers who know more than I, for thee hast shown me the true errors of mine ways. :lol:

Seeya guys later and thans for thine help
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#5
Well, first of all: I answered you question, then I got depressed, 'cuz I just saw at that time your RTFM moment and I remembered your self-confidence and your so-called "intermediate skills". Sorry if I affected your enormous ego, but you know, the bigger the things are, the more difficult to miss. [Image: diablotin.gif]
img]http://usuarios.vtr.net/~disaster/sigs/annoyizer.php[/img]
Reply
#6
WHAHAHA

I suck and I know it
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#7
Just discovered na_th_an's bit of code to empty the buffer and it was just what I was looking for. Many thanx man !

while inkey$ <> "":wend

Simple but effective
Reply
#8
Compare the length, rather than the string. It's faster.

For example,
Code:
DO WHILE LEN(INKEY$) = 0: LOOP
Reply
#9
even faster:

Code:
WHILE LEN(INKEY$):WEND
WHILE NOT LEN(INKEY$):WEND
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#10
The fastest way to clear the keybuffer (but you cant read from it when you do this)

Code:
DEF SEG=0: POKE &H41A, PEEK(&H41C)
DEF SEG
(Arghh,,,, why does a line not end in ;?? To much C coding Wink)

You can also read from the keyboard by this:

Code:
keycode = INP(&H60)

And if you go to the code post, you can have pure qb multikey!
b]Hard Rock[/b]
[The Stars Dev Company] [Metal Qb flopped] [The Terror]
Stop Double Posts!
Whats better? HTML or Variables?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)