input without input

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

User avatar
yacinator
Full Member
Posts:33
Joined:Sun Dec 21, 2003 12:02 am
input without input

Post by yacinator » Tue Mar 09, 2004 11:49 am

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

Artie
Jr. Member
Posts:23
Joined:Fri Feb 06, 2004 12:48 am
Location:Florida
Contact:

Re: input without input

Post by Artie » Tue Mar 09, 2004 2:41 pm

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.

Guest

Re: input without input

Post by Guest » Tue Mar 09, 2004 5:36 pm

Hi,

Look up INKEY$ in the HELP.

Pappy

User avatar
yacinator
Full Member
Posts:33
Joined:Sun Dec 21, 2003 12:02 am

Re: input without input

Post by yacinator » Thu Mar 11, 2004 2:03 am

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

Guest

Re: input without input

Post by Guest » Thu Mar 11, 2004 9:05 pm

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

User avatar
yacinator
Full Member
Posts:33
Joined:Sun Dec 21, 2003 12:02 am

Re: input without input

Post by yacinator » Fri Mar 12, 2004 2:57 am

thanks it worked   :)

User avatar
yacinator
Full Member
Posts:33
Joined:Sun Dec 21, 2003 12:02 am

Re: input without input

Post by yacinator » Fri Mar 12, 2004 4:05 am

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

Dr_Davenstein
QBasic God
Posts:166
Joined:Tue Mar 25, 2003 12:45 am
Location:U.S.A.
Contact:

Re: input without input

Post by Dr_Davenstein » Fri Mar 12, 2004 9:00 am

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!

User avatar
yacinator
Full Member
Posts:33
Joined:Sun Dec 21, 2003 12:02 am

Re: input without input

Post by yacinator » Fri Mar 12, 2004 11:42 am

no chr4(27) is not esc it's left arrow!!!!! :P. 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

Guest

Re: input without input

Post by Guest » Sat Mar 13, 2004 9:14 am

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)

User avatar
yacinator
Full Member
Posts:33
Joined:Sun Dec 21, 2003 12:02 am

Re: input without input

Post by yacinator » Sat Mar 13, 2004 9:48 am

thx and i'm srry u were right  

User avatar
yacinator
Full Member
Posts:33
Joined:Sun Dec 21, 2003 12:02 am

Re: input without input

Post by yacinator » Tue Mar 16, 2004 10:33 am

can somebody plz tell me how F1-12 , Ctrl , Alt and shift are identified by inkey$? (i won't be rude like that anymore)

Guest

Re: input without input

Post by Guest » Tue Mar 16, 2004 11:56 am

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..

Artie
Jr. Member
Posts:23
Joined:Fri Feb 06, 2004 12:48 am
Location:Florida
Contact:

Re: input without input

Post by Artie » Tue Mar 16, 2004 2:15 pm

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

User avatar
yacinator
Full Member
Posts:33
Joined:Sun Dec 21, 2003 12:02 am

Re: input without input

Post by yacinator » Sun Mar 21, 2004 6:14 am

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?

Post Reply