key problem

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
paulunknown

key problem

Post 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?
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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... :wink:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
paulunknown

Post by paulunknown »

o i see
thanks
Is there such thing as OUTKEY$?
or something that sense the letting go of a key?
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post 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."
 
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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 
:wink:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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: :wink:

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
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
paulunknown

Post 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?
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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:

Code: Select all

UKey$ = OUTKEY$
Like you would with INKEY$.. :wink:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
paulunknown

Post 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
User avatar
The Awakened
Veteran
Posts: 144
Joined: Sun Aug 07, 2005 1:51 am

Post by The Awakened »

Code: Select all


DO
    t = t - 1
    IF t = 1 THEN EXIT LOOP
    b = b - 1
LOOP UNTIL b = 1

"Sorry for beating you up with a baseball bat Julian, but I DID think that you were a samsquanch."
pauluknown

Post by pauluknown »

ok thanks
paulunknown

Post by paulunknown »

actually it is exit do -_-
thanks anyways at least i fixed a problem
paulunknown

Post by paulunknown »

how do i make something go one way then after a key is pressed it goes the other way?(moving continuously)
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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
:wink:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Post Reply