input without input
Moderators:Administrator, Global Moderator
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
can somebody plz help
Re: input without input
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.
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
Can somebody please tell me how to use the inkey$ thing? I tried something like this :
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
Code: Select all
CLS
LET a$=INKEY$
IF a$="a" THEN
PRINT "left"
ELSEIF a$="d" THEN
PRINT "right"
ENDIF
END
Re: input without input
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
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
thanks it worked
Re: input without input
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
-
- QBasic God
- Posts:166
- Joined:Tue Mar 25, 2003 12:45 am
- Location:U.S.A.
- Contact:
Re: input without input
the (esc) key is CHR$(27).
Come check out [url=http://www.freebasic.net/forum/index.php]FreeBASIC[/url]. The syntax is based on QuickBasic, but it expands to use pointers, operator overloading, etc... The list goes on and on!
Re: input without input
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
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.
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
thx and i'm srry u were right
Re: input without input
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
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..
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
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
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
i tried this :
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?
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