www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/07/13:20:44

From: "Roland Moritz" <hotel DOT moritz AT utanet DOT at>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How to empty the keyboard buffer
Date: Thu, 7 Oct 1999 17:08:01 +0200
Organization: UTANET Newsserver
Lines: 50
Message-ID: <7tibo0$44f$1@rohrpostix.uta4you.at>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 991005095415 DOT 2899L-100000 AT is>
NNTP-Posting-Host: mibeu01-0469.utaonline.at
X-Trace: rohrpostix.uta4you.at 939307584 4239 212.152.129.215 (7 Oct 1999 14:46:24 GMT)
X-Complaints-To: news-admin AT utanet DOT at
NNTP-Posting-Date: 7 Oct 1999 14:46:24 GMT
X-Newsreader: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Eli Zaretskii schrieb in Nachricht ...
>
>On Mon, 4 Oct 1999, Roland Moritz wrote:
>
>> And now my question is, how do I empty the keyboard buffer everytime the
>> loop is through, since I don't want, for example, that if a message is
shown
>> for 5 Seconds, and the player pushes some keys, that they will be used as
>> keyboard input the next time the loop is running through, since there are
>> still keys in the buffer...I've tried it with something simple like
>>
>> while (kbhit()
>>   c = getch();
>>
>> But it does'nt work...
>
>The above *is* the way to empty the keyboard.  If it doesn't work for
>you, please post the shortest test program that can be compiled and
>that demonstrates how does it fail.  Please also tell how do you run
>the test program and what do you expect to happen if it did work.

Okay, the shortest test program is the following:

#include <stdlib.h>
#include <stdio.h>

#include "allegro.h"

int main()
{
  int c;

  allegro_init();
  install_timer();
  do
  {
    c = getch();
    rest(1000);
    while (kbhit())
      c = getch();
  }
  while (c != 27);
}

It basically does the same that happens in a game loop, but doesn't work
(When I press a button for a longer time, I hear a loud beeping, which
means, that the kb-buffer is full, right?)


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019