QB64 inkey$ requires multiple presses

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

Albert
Coder
Posts: 14
Joined: Mon Jul 04, 2016 10:30 am

QB64 inkey$ requires multiple presses

Postby Albert » Mon Jul 04, 2016 10:33 am

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?

User avatar
burger2227
Veteran
Posts: 2144
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: QB64 inkey$ requires multiple presses

Postby burger2227 » Mon Jul 04, 2016 12:12 pm

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"
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : http://www.QB64.NET
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0

Albert
Coder
Posts: 14
Joined: Mon Jul 04, 2016 10:30 am

Re: QB64 inkey$ requires multiple presses

Postby Albert » Mon Jul 04, 2016 1:49 pm

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

User avatar
burger2227
Veteran
Posts: 2144
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: QB64 inkey$ requires multiple presses

Postby burger2227 » Mon Jul 04, 2016 4:28 pm

That is why we are here !
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : http://www.QB64.NET
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0


Return to “QBASIC and QB64 Questions & Answers”

Who is online

Users browsing this forum: No registered users and 9 guests