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

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

I have a problem with INKEY$ and _DELAY

Postby Albert » Tue Aug 23, 2016 5:17 pm

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

Postby Albert » Tue Aug 23, 2016 5:28 pm

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: 2144
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: I have a problem with INKEY$ and _DELAY

Postby burger2227 » Tue Aug 23, 2016 5:43 pm

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 : 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: I have a problem with INKEY$ and _DELAY

Postby Albert » Tue Aug 23, 2016 5:54 pm

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: 2144
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: I have a problem with INKEY$ and _DELAY

Postby burger2227 » Tue Aug 23, 2016 7:52 pm

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 : 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: I have a problem with INKEY$ and _DELAY

Postby Albert » Wed Aug 24, 2016 5:08 am

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


Return to “QBASIC and QB64 Questions & Answers”

Who is online

Users browsing this forum: Bing [Bot] and 9 guests