Page 1 of 1

QB64 inkey$ requires multiple presses

Posted: Mon Jul 04, 2016 10:33 am
by Albert
so QB64 inkey$ requires multiple presses to register a key press
e.g. :

DO
IF inkey$ = "a" THEN GOTO 100
IF inkey$ = "s" THEN GOTO 200
IF inkey$ = "d" THEN GOTO 300
LOOP UNTIL inkey$ = "a" OR inkey$ = "s" OR inkey$ = "d"

100 PRINT "You pressed A."
200 PRINT "You pressed S."
300 PRINT "You pressed D."

how do I counter this bug?

Re: QB64 inkey$ requires multiple presses

Posted: Mon Jul 04, 2016 12:12 pm
by burger2227
Not a bug! You were reading the INKEY$ function many times and results were read and changed each time:

Code: Select all

DO 
K$ = LCASE$(INKEY$) ' K holds first Inkey$ result and lowers uppercase types too
LOOP UNTIL K$ = "a" OR K$ = "s" OR K$ = "d" 

IF K$ = "a" THEN PRINT "You pressed A."
IF K$ = "s" THEN PRINT "You pressed S."
IF K$ = "d" THEN PRINT "You pressed D." 
Since case is lower you do not need to check for both "d" and "D"

Re: QB64 inkey$ requires multiple presses

Posted: Mon Jul 04, 2016 1:49 pm
by Albert
burger2227 wrote:Not a bug! You were reading the INKEY$ function many times and results were read and changed each time:

Code: Select all

DO 
K$ = LCASE$(INKEY$) ' K holds first Inkey$ result and lowers uppercase types too
LOOP UNTIL K$ = "a" OR K$ = "s" OR K$ = "d" 

IF K$ = "a" THEN PRINT "You pressed A."
IF K$ = "s" THEN PRINT "You pressed S."
IF K$ = "d" THEN PRINT "You pressed D." 
Since case is lower you do not need to check for both "d" and "D"
thank you really much! :D
I would claim this best answer if I could :P

Re: QB64 inkey$ requires multiple presses

Posted: Mon Jul 04, 2016 4:28 pm
by burger2227
That is why we are here !