Page 1 of 2
input without input
Posted: Tue Mar 09, 2004 11:49 am
by yacinator
i was wondering how can qb detect key strokes without the input statement. i mean in a game you can't have a input statement "which way do u wanna move?"
can somebody plz help
Re: input without input
Posted: Tue Mar 09, 2004 2:41 pm
by Artie
You can do this, but it starts to get complicated, by reading the keyboard buffer, or something like that.
Check out this thread over at QbasicNews.com:
http://forum.qbasicnews.com/viewtopic.php?t=5421
Be sure to read the "links" in the "links. It'll take some reading and work to figure it out, but not impossible.
Re: input without input
Posted: Tue Mar 09, 2004 5:36 pm
by Guest
Hi,
Look up INKEY$ in the HELP.
Pappy
Re: input without input
Posted: Thu Mar 11, 2004 2:03 am
by yacinator
Can somebody please tell me how to use the inkey$ thing? I tried something like this :
Code: Select all
CLS
LET a$=INKEY$
IF a$="a" THEN
PRINT "left"
ELSEIF a$="d" THEN
PRINT "right"
ENDIF
END
and I get a blank screen with "press any key to continue". I press a key and it goes back to the editor mode. ??? Can somebody please give me a sample program with the inkey$ statement please
Re: input without input
Posted: Thu Mar 11, 2004 9:05 pm
by Guest
Hi,
INKEY$ does not wait for a key so a loop is needed to wait for a key to be hit
ie.
PRINT "START"
i$ = ""
WHILE i$ = ""
i$ = INKEY$
WEND
PRINT i$
PRINT "DONE"
This one of many ways I've seem INKEY$ used.
Hope this helps.
Pappy
BTW
Programmers Heaven and
Tek-Tips
have BASIC forums which have more people in them
Re: input without input
Posted: Fri Mar 12, 2004 2:57 am
by yacinator
thanks it worked
Re: input without input
Posted: Fri Mar 12, 2004 4:05 am
by yacinator
just one little thing. i looked up the inkey$ statement in a book from which i'm learnig qbasic and it said that keys like esc or arrow keys are identified by 2 chr$ statements : chr$(0) and chr$(32) (space). but in the ascii table there's no chr$ esc. can somebody tell me how inkeky$ id's esc plz
Re: input without input
Posted: Fri Mar 12, 2004 9:00 am
by Dr_Davenstein
the (esc) key is CHR$(27).
Re: input without input
Posted: Fri Mar 12, 2004 11:42 am
by yacinator
no chr4(27) is not esc it's left arrow!!!!!
. can somebody tell me how to make inkey$ id arrow keys and stuff the thing that was in the book i tried but it doesn't work
Re: input without input
Posted: Sat Mar 13, 2004 9:14 am
by Guest
Yes, INKEY$ identifies the
escape key as
character #27...
OR CHR$(27)....
Yes it is! You shouldn't be so rude when someone helps you. I think I know what the hell I'm talking about dude.
Code: Select all
DO
X$=INKEY$
Print "PRESS THE (ESC) KEY DUMMY!!!"
LOOP UNTIL X$=CHR$(27)
Re: input without input
Posted: Sat Mar 13, 2004 9:48 am
by yacinator
thx and i'm srry u were right
Re: input without input
Posted: Tue Mar 16, 2004 10:33 am
by yacinator
can somebody plz tell me how F1-12 , Ctrl , Alt and shift are identified by inkey$? (i won't be rude like that anymore)
Re: input without input
Posted: Tue Mar 16, 2004 11:56 am
by Guest
Hello Yacinator.
I think that you are asking for Scancodes. If you jut enter scancodes or scan codes into your browser you will have lots of sites to choose from with lotsa info on how to use them.
Good luck
Val..
Re: input without input
Posted: Tue Mar 16, 2004 2:15 pm
by Artie
Hi Yac; here's what I do:
The function keys and arrow keys are two-byte codes, so test for all possible one-byte codes first.
KeyCatcher:
a$ = INKEY$
IF a$ = "" THEN GOTO KeyCatcher
IF a$ = CHR$(27) THEN END
' Put all your other key press tests here.
IF LEN(a$) = 2 THEN a$ = RIGHT$(a$, 1)
IF a$ = CHR$(72) THEN GOTO UpArrowRoutine
IF a$ = CHR$(80) THEN GOTO DownArrowRoutine
IF a$ = CHR$(75) THEN GOTO LeftArrowRoutine
IF a$ = CHR$(77) THEN GOTO RightArrowRoutine
GOTO KeyCatcher
Thats one example. Try it.
Artie
Re: input without input
Posted: Sun Mar 21, 2004 6:14 am
by yacinator
i tried this :
Code: Select all
CLS
FOR i = 1 TO 64
LET TIME = TIMER
DO
LET a$ = INKEY$
LOOP UNTIL TIMER = TIME + 5
LET b = LEN(a$)
IF b = 1 THEN
PRINT "the key u pressed is 1 characters long"
ELSEIF b = 2 THEN
PRINT "the key u pressed is 2 characters long"
END IF
PRINT i
INPUT "proceed?", dummy$
NEXT i
PRINT "ready to continue?"
FOR i = 91 TO 255
LET TIME = TIMER
DO
LET a$ = INKEY$
LOOP UNTIL TIMER = TIME + 5
LET b = LEN(a$)
IF b = 1 THEN
PRINT "the key u pressed is 1 characters long"
ELSEIF b = 2 THEN
PRINT "the key u pressed is 2 characters long"
END IF
PRINT i
INPUT "proceed?", dummy$
NEXT i
END
and it wouldn't show anything. then i tried to change the line ELSEIF b=2 THEN to plan ELSE and it would always say 2. how do i fix that?