Microsoft KB Archive/107427

= BUG: getch Returns Incorrect Extended Key Codes =

PSS ID Number: 107427

Article Last Modified on 10/16/2002

-

The information in this article applies to:

 The C Run-Time (CRT), when used with:  Microsoft Visual C++, 32-bit Editions 1.0

 Microsoft Visual C++, 32-bit Editions 2.0

 Microsoft Visual C++, 32-bit Editions 2.1

 Microsoft Visual C++, 32-bit Editions 4.0</li></ul>

 Microsoft Visual C++, 32-bit Editions 4.1</li></ul>

 Microsoft Visual C++, 32-bit Editions 4.2</li></ul>

 Microsoft Visual C++, 32-bit Editions 5.0</li></ul>

 Microsoft Visual C++, 32-bit Editions 6.0</li></ul>

 Microsoft Visual C++ .NET (2002)</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q107427

<div class="notice_section">

<div class="symptoms_section">

SYMPTOMS
The getch run-time library function fails to return the correct extended character code for certain key sequences. There are two known situations in which incorrect codes are generated:
 * The ALT key is combined with the ASCII characters A - Z. -or-


 * The RIGHT CTRL key is combined with any of the function or editing keys.

With Visual C++ versions 2.x and later, only the first error (error with ALT key) occurs.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

<div class="moreinformation_section">

MORE INFORMATION
In the sample code below, the ALT key combined with any ASCII character returns the ASCII character code instead of the extended character code. The RIGHT CTRL key combined with any of the function or editing keys also fails with Visual C++ 1.0, returning the code for the function or editing key alone. The LEFT CTRL key combined with a function key or editing key returns the correct code. The set of affected editing keys are: END, PAGE UP, PAGE DOWN, HOME, RIGHT ARROW, and LEFT ARROW.

The table below demonstrates some of the actual versus expected values that result when the sample below is run with the input shown: <pre class="fixed_text">Input           Expected          Actual                VC 6.0

ALT+C           0 - 2eH           63H    (C)             63H RT CTRL+F4      0 - 61H         0 - 3eH  (F4)           0 - 61H RT CTRL+PAGE UP 0 - 84H         0 - 49H  (PAGEUP)      e0 - 86H RT CTRL+END     0 - 75H         0 - 4fH  (END)          0 - 75H

Sample Code
/* Compile options needed: none */

void main(void) {     int testChar;

do { testChar = getch; printf(&quot;%x - &quot;, testChar); testChar = getch; printf(&quot;%x \n&quot;, testChar); } while (testChar != 0x001B); /* Repeat until ESC key*/ }

Additional query words: kbVC400bug

Keywords: kbBug kbCRT KB107427

Technology: kbAudDeveloper kbCRT kbvc100 kbVC200 kbVC210 kbVC32bitSearch kbVC400 kbVC410 kbVC420 kbVC500 kbVC500Search kbVC600 kbVCNET kbVCsearch

-

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

© 2003 Microsoft Corporation. All rights reserved.