Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: Patch for Numpad issue on Win32  (Read 1062 times)

ltan

  • Newbie
  • *
  • Karma: +0/-0
  • Posts: 1
    • View Profile
Patch for Numpad issue on Win32
« on: March 27, 2008, 03:02:57 AM »

Hi all,

Win32Keyboard::_translateText never returns any values when pressing numpad keys, even with numlock on. The reason for this is that MapVirtualKeyEx doesn't take the numlock status into account. There doesn't seem to be a good way to work around this, so I implemented the following solution:

Win32Keyboard.cpp (186)

//--------------------------------------------------------------------------------------------------//
int Win32Keyboard::_translateText( KeyCode kc )
{
   if( mTextMode == Off )
      return 0;

   BYTE keyState[256];
   HKL  layout = GetKeyboardLayout(0);
   if( GetKeyboardState(keyState) == 0 )
      return 0;

   if( keyState[VK_NUMLOCK] & 0x7 )
   {
      // Numpad handling
      switch( kc )
      {
         case KC_NUMPAD0:
            return '0';
         case KC_NUMPAD1:
            return '1';
         case KC_NUMPAD2:
            return '2';
         case KC_NUMPAD3:
            return '3';
         case KC_NUMPAD4:
            return '4';
         case KC_NUMPAD5:
            return '5';
         case KC_NUMPAD6:
            return '6';
         case KC_NUMPAD7:
            return '7';
         case KC_NUMPAD8:
            return '8';
         case KC_NUMPAD9:
            return '9';
      
         default:
            break;
      }

   }

        // Special case for KC_DIVIDE as MapVirtualKeyEx returns 0 for this key.
        if( kc == KC_DIVIDE )
                return '/';

Perhaps this could be included for the next version?
Logged