Microsoft KB Archive/44895

= The kbhit function does not take the character out of the buffer =

Article ID: 44895

Article Last Modified on 1/5/2006

-

APPLIES TO

 The C Run-Time (CRT), when used with:  Microsoft C Professional Development System 6.0a

 Microsoft C Professional Development System 6.0a

 Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.5 Professional Edition</li></ul>

 Microsoft Visual C++ 1.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Visual C++ 5.0 Standard Edition</li></ul>

 Microsoft Visual C++ 6.0 Service Pack 5</li></ul>

 Microsoft Visual C++ 2005 Express Edition</li></ul>

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q44895

<div class="notice_section">

<div class="notice_section">

Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code. Microsoft Visual C++ 2005 supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model..

<div class="summary_section">

SUMMARY
When an application tests the value returned by the kbhit function, the application must explicitly remove the character from the keyboard buffer after entering the keystroke. Otherwise, kbhit continues to return TRUE.

The following code example demonstrates the situation:

Sample Code
/* * Compiler options needed: None */


 * 1) include <conio.h>

void main(void) {  while (!kbhit) ;         // Waits for keystroke while (kbhit) getch;  // Empties buffer while (!kbhit) ;         // Waits for keystroke }

Keywords: kbinfo kbcode KB44895

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.