help on limiting keys
help on limiting keys
Why when I use this:
DO
SLEEP
LOOP UNITL INKEY$ = "w"
I get stuck in the loop even when i press "w".
What can I do to make it so that only certain keys will allow someone to continue?
DO
SLEEP
LOOP UNITL INKEY$ = "w"
I get stuck in the loop even when i press "w".
What can I do to make it so that only certain keys will allow someone to continue?
Code: Select all
DO
SLEEP
LOOP UNITL lcase$(INKEY$) = "w"
That shouldnt be needed, and is not needed.Antoni wrote:Code: Select all
DO SLEEP LOOP UNITL lcase$(INKEY$) = "w"
I have left this dump.
Try this
I use
It pops out of the loop when you press anything. Then you can test what was pressed. For example, if k$=chr$(27) then the Esc key was pressed.
Code: Select all
Do
k$=inkey$
loop until len(k$)
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
--- Time flies like an arrow, but fruit flies like a banana ---
-
- Newbie
- Posts: 3
- Joined: Wed Jan 18, 2006 10:34 pm
- Location: Windsor, Ontario
-
- Veteran
- Posts: 109
- Joined: Thu Feb 10, 2005 12:38 pm
i mainly use
Code: Select all
do
key$=inkey$
loop until key$ <> ""
-
- Coder
- Posts: 17
- Joined: Sat Aug 27, 2005 10:26 am
I tried
and it doesn't work.
Code: Select all
DO
LOOP UNTIL INKEY$ = "w"
-
- Coder
- Posts: 17
- Joined: Sat Aug 27, 2005 10:26 am
- The Awakened
- Veteran
- Posts: 144
- Joined: Sun Aug 07, 2005 1:51 am
Well, for starters, CASE IS is not a command, it's just CASE.
And it doesn't matter what INKEY is after the loop. As soon as someone presses w, it exits the loop and you might as well just scrap the whole select case thing and go x = x + 1. Just do this:
And it doesn't matter what INKEY is after the loop. As soon as someone presses w, it exits the loop and you might as well just scrap the whole select case thing and go x = x + 1. Just do this:
Code: Select all
DO
LOOP UNTIL INKEY$ = "w"
x = x + 1
"Sorry for beating you up with a baseball bat Julian, but I DID think that you were a samsquanch."
-
- Coder
- Posts: 17
- Joined: Sat Aug 27, 2005 10:26 am
Think of the keyboard buffer as a queue..paulunknown wrote:There's another problem though.The select case part don't seem to work.Code: Select all
DO LOOP UNTIL INKEY$ = "w" SELECT CASE INKEY$ CASE IS = "w" x =x -1 END SELECT
Every time you call INKEY, the oldest key gets returned (the key that has spent the most time in the queue)
As an example, lets say the user press:
A, B, C
First char in would be A, now, the first time you call INKEY, it will return A.
However, second time you call it, it will return the next character in the queue, which is B in our example.
Fixed:
Code: Select all
DO
k$ = INKEY$
LOOP UNTIL k$ = "w"
SELECT CASE k$
[...]
I have left this dump.
You bonehead...that specific code is never gonna work. k$ is ALWAYS going to be w after the loop because the loop won't end until it is so your SELECT CASE will only ever work with CASE "w". Silly Swede...Z!re wrote:Code: Select all
DO k$ = INKEY$ LOOP UNTIL k$ = "w" SELECT CASE k$ [...]
Indeed!Think of the keyboard buffer as a queue..
I've used:
Code: Select all
For i=1 to 16
dummy=inkey$
next i
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
--- Time flies like an arrow, but fruit flies like a banana ---
- The Awakened
- Veteran
- Posts: 144
- Joined: Sun Aug 07, 2005 1:51 am
edit: Yeah, code didn't work before. Here's something that does work:
Code: Select all
DO
SELECT CASE INKEY$
CASE "a"
'do whatever
EXIT DO
CASE "b"
'do whatever
EXIT DO
END SELECT
LOOP
Last edited by The Awakened on Tue Jan 24, 2006 2:57 pm, edited 1 time in total.
"Sorry for beating you up with a baseball bat Julian, but I DID think that you were a samsquanch."
Sorry...
Sorry, Awakened, but that won't work. Inkey$ scans the keyboard one time when it's executed. The first keystroke will pop the program out of the first loop. The case structure will execute based upon the SECOND keystroke which will, in THIS case typically be blank or the null string.
EDIT: Yup, that's better...
EDIT: Yup, that's better...
Last edited by Zim on Wed Jan 25, 2006 12:49 pm, edited 1 time in total.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
--- Time flies like an arrow, but fruit flies like a banana ---
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
I use:
Or, to test for other keys, you can use ASCII, as shown.
They *should* work, but are untested.
Code: Select all
Key$ = ""
WHILE Key$ = ""
Key$ = INKEY$
WEND
SELECT CASE LCASE$(Key$) 'LCASE$ is optional
CASE "w"
[. . .]
CASE "e"
[. . .]
END SELECT
Code: Select all
SELECT CASE ASC(LCASE$(Key$))
CASE 27
[. . .] 'ESC was pressed.
END SELECT
-
- Coder
- Posts: 17
- Joined: Sat Aug 27, 2005 10:26 am