Page 1 of 1
key problem
Posted: Wed Aug 24, 2005 5:48 pm
by paulunknown
here is what i want to do in half human half qb language:
DO
key$ = INKEY$
LOOP UNTIL key$ = "q" or "w" or "e" or "r"
The problem is that i could only use 'or' once. What options do i have to get the same effect?
Posted: Wed Aug 24, 2005 5:57 pm
by Rattrapmax6
Like this:
Code: Select all
DO
Key$ = UCASE$(INPUT$)
LOOP UNTIL Key$ = "Q" OR Key$ = "W" OR Key$ = "E" OR Key$ = "R"
Notice you need Key$ on each check....
Note: UCASE$ just makes everything capital and case insencitive...

Posted: Wed Aug 24, 2005 6:19 pm
by paulunknown
o i see
thanks
Is there such thing as OUTKEY$?
or something that sense the letting go of a key?
Posted: Wed Aug 24, 2005 6:37 pm
by Patz QuickBASIC Creations
Waiting for a release of a key:
Code: Select all
While inkey$ = ""
WEND
While inkey$ <> ""
key$ = inkey$
WEND
Print "You pressed and released the ";key$;" key."
Posted: Wed Aug 24, 2005 7:58 pm
by Rattrapmax6
Um.. that doesn't work,.. it needs to be:
Code: Select all
While key$ = ""
key$ = inkey$
WEND
Print "You pressed and released the ";key$;" key."
Or this:
Code: Select all
DO
key$ = INKEY$
LOOP UNTIL key$ <> ""
PRINT "You pressed: "; key$
SLEEP

Posted: Wed Aug 24, 2005 8:28 pm
by Rattrapmax6
Here... I made a OUTKEY$ routine,.. works if you use a delay... INKEY$ is all jumpy, so with out it, it messes up a lil:
Code: Select all
DECLARE FUNCTION OUTKEY$ ()
DO
T! = TIMER
Press$ = INKEY$
Release$ = OUTKEY$
LOCATE 1, 1: PRINT "Pressed: "; Press$; " Released: "; Release$; " "
DO: LOOP UNTIL (TIMER - T!) >= .2
LOOP UNTIL Press$ = CHR$(27)
FUNCTION OUTKEY$
STATIC PRESS001
STATIC WAITKEY001$
KEY001$ = INKEY$
IF PRESS001 <> 1 AND KEY001$ <> "" THEN PRESS001 = 1: WAITKEY001$ = KEY001$': OUTKEY = ""
IF PRESS001 = 1 AND KEY001$ = "" THEN OUTKEY$ = WAITKEY001$: PRESS001 = 0
END FUNCTION
Posted: Thu Aug 25, 2005 10:04 am
by paulunknown
your routine is so complicated that i don't get much of it
i'll stick with the simpler codes but what does 'WEND' do?
Posted: Thu Aug 25, 2005 2:06 pm
by Rattrapmax6
WEND works with WHILE to form a loop:
Code: Select all
WHILE X = 1
'Code here
WEND 'loop until X <> 1
I normaly just use DO..LOOP,...
btw, my function copied and pasted into QB would be out of the way, all you need to do to use it is:
Like you would with INKEY$..

Posted: Thu Aug 25, 2005 9:58 pm
by paulunknown
another question
if i want to do this:
DO
t = t - 1
LOOP UNTIL t or b = 1
b=b - 1
LOOP UNTIL... t or b = 1
1 do can only support 1 loop but i need i for 2 loops because if t = 1, i don't want b to subtract 1. If t = 1 i want it to stop imediately if = to 1
how do i do that
Posted: Thu Aug 25, 2005 10:25 pm
by The Awakened
Code: Select all
DO
t = t - 1
IF t = 1 THEN EXIT LOOP
b = b - 1
LOOP UNTIL b = 1
Posted: Thu Aug 25, 2005 11:14 pm
by pauluknown
ok thanks
Posted: Fri Aug 26, 2005 11:26 am
by paulunknown
actually it is exit do -_-
thanks anyways at least i fixed a problem
Posted: Fri Aug 26, 2005 2:17 pm
by paulunknown
how do i make something go one way then after a key is pressed it goes the other way?(moving continuously)
Posted: Fri Aug 26, 2005 5:09 pm
by Rattrapmax6
Hmm... like this:
Code: Select all
SCREEN 13
x = 160 'Center of screen
DO 'Main loop
press$ = UCASE$(INKEY$) 'Look for keypresses
IF press$ = "A" THEN x = x - 1 'If a, move left
IF press$ = "S" THEN x = x + 1 'If s, move right
PSET(X, 100), 10 'Put object on moved cord..
LOOP UNTIL INKEY$ = CHR$(27)'End on Esc key
