Microsoft KB Archive/77550

{|
 * width="100%"|

HOWTO: Differentiate Between the Two ENTER Keys

 * }

Q77550

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK)
 * Microsoft Windows Software Development Kit (SDK) 3.1

-

SUMMARY
An application may find it useful to differentiate between the user pressing the ENTER key on the standard keyboard and the ENTER key on the numeric keypad. Either action creates a WM_KEYDOWN message and a WM_KEYUP message with wParam set to the virtual key code VK_RETURN. When the application passes these messages to TranslateMessage, the application receives a WM_CHAR message with wParam set to the corresponding ASCII code 13.

To differentiate between the two ENTER keys, test bit 24 of lParam sent with the three messages listed above. Bit 24 is set to 1 if the key is an extended key; otherwise, bit 24 is set to 0 (zero). The contents of lParam for these messages is documented in the &quot;Microsoft Windows Software Development Kit Reference Volume 1&quot; for version 3.0 of the SDK and in the SDK Reference Volume 3, &quot;Messages, Structures, and Macros.&quot;

Because the keys in the numeric keypad (along with the function keys) are extended keys, pressing ENTER on the numeric keypad results in bit 24 of lParam being set, while pressing the ENTER key on the standard keyboard results in bit 24 clear.

The following code sample demonstrates differentiating between these two ENTER keys:

  case WM_KEYDOWN: if (wParam == VK_RETURN)   // ENTER pressed if (lParam & 0x1000000L) // Test bit 24 of lParam {           // ENTER on numeric keypad }        else {           // ENTER on the standard keyboard }     break; Additional query words:

Keywords : _IK kbInput kbKeyIn kbOSWin2000 kbSDKWin32 kbGrpDSUser

Issue type : kbhowto

Technology : kbWin32SDKSearch kbAudDeveloper kbWin3xSearch kbSDKSearch kbWin32sSearch kbWinSDKSearch kbWinSDK310