I have a problem with INKEY$ and _DELAY

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

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

I have a problem with INKEY$ and _DELAY

Post by Albert »

Code: Select all

SCREEN _NEWIMAGE(800, 600, 32)

PRINT "Press ENTER to continue."

DO
LOOP UNTIL INKEY$ = CHR$(13)

_DELAY 1

PRINT "Press ENTER again to quit."

DO
LOOP UNTIL INKEY$ = CHR$(13)
in this example you can press enter twice without the second print being displayed but it still ends the application
if you didn't get the problem maybe u can test it out by yourself, THANK YOU IN ADVANCE !!!
Albert
Coder
Posts: 14
Joined: Mon Jul 04, 2016 10:30 am

Re: I have a problem with INKEY$ and _DELAY

Post by Albert »

Albert wrote:

Code: Select all

SCREEN _NEWIMAGE(800, 600, 32)

PRINT "Press ENTER to continue."

DO
LOOP UNTIL INKEY$ = CHR$(13)

_DELAY 1

PRINT "Press ENTER again to quit."

DO
LOOP UNTIL INKEY$ = CHR$(13)
in this example you can press enter twice without the second print being displayed but it still ends the application
idk if it's a bug or i if i just screwed up but i need some help :D
if you didn't get the problem maybe u can test it out by yourself, THANK YOU IN ADVANCE !!!
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: I have a problem with INKEY$ and _DELAY

Post by burger2227 »

What are you trying to do? Worked for me.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
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: I have a problem with INKEY$ and _DELAY

Post by Albert »

burger2227 wrote:What are you trying to do? Worked for me.
you can press enter twice without waiting for the delay and once the time passes it just ends the application
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: I have a problem with INKEY$ and _DELAY

Post by burger2227 »

INKEY$ reads the keyboard buffer. IE the buffer holds the keys pressed until read.

Code: Select all

PRINT "Press ENTER to continue."

DO
LOOP UNTIL INKEY$ = CHR$(13)

_DELAY 2

PRINT "Press ENTER again to quit."

DO
  PRINT INKEY$;
LOOP UNTIL INKEY$ = CHR$(13)

Press all the keys you want during the delay and see what is printed. SLEEP will keep the keys in the buffer too.

To clear the buffer use: DO UNTIL INKEY$ = "": LOOP

Otherwise an INPUT later may pick up the extra key presses.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
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: I have a problem with INKEY$ and _DELAY

Post by Albert »

burger2227 wrote:INKEY$ reads the keyboard buffer. IE the buffer holds the keys pressed until read.

Code: Select all

PRINT "Press ENTER to continue."

DO
LOOP UNTIL INKEY$ = CHR$(13)

_DELAY 2

PRINT "Press ENTER again to quit."

DO
  PRINT INKEY$;
LOOP UNTIL INKEY$ = CHR$(13)

Press all the keys you want during the delay and see what is printed. SLEEP will keep the keys in the buffer too.

To clear the buffer use: DO UNTIL INKEY$ = "": LOOP

Otherwise an INPUT later may pick up the extra key presses.
this solved my problem, thank you!

btw I found _KEYCLEAR command and I think it's easier to use it than what you taught me :D ty again
Post Reply