INKEY$ - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html) +--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html) +--- Thread: INKEY$ (/thread-135.html) Pages:
1
2
|
INKEY$ - NovaProgramming - 02-02-2003 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 ) INKEY$ - Hexadecimal Disaster - 02-02-2003 *cries again* IF INKEY$ <> "" THEN GOTO 1 That's ONE of the N^999 solutions to your question! *looks hopeless to his shotgun* INKEY$ - na_th_an - 02-02-2003 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. 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. INKEY$ - NovaProgramming - 02-05-2003 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 INKEY$ - Hexadecimal Disaster - 02-05-2003 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. INKEY$ - NovaProgramming - 02-06-2003 WHAHAHA I suck and I know it INKEY$ - buckytomsk - 04-13-2003 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 INKEY$ - DrV - 04-15-2003 Compare the length, rather than the string. It's faster. For example, Code: DO WHILE LEN(INKEY$) = 0: LOOP INKEY$ - na_th_an - 04-15-2003 even faster: Code: WHILE LEN(INKEY$):WEND INKEY$ - Hard Rock - 04-15-2003 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) 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! |