src/video/windib/SDL_dibevents.c
changeset 1852 eb2d5480ae95
parent 1526 89f90f32f6c0
child 1895 c121d94672cb
child 3868 b2f59aadec0d
     1.1 --- a/src/video/windib/SDL_dibevents.c	Wed May 17 23:42:48 2006 +0000
     1.2 +++ b/src/video/windib/SDL_dibevents.c	Thu May 18 03:24:10 2006 +0000
     1.3 @@ -122,8 +122,16 @@
     1.4  					} else if (state[SDLK_RSHIFT] == SDL_RELEASED && (GetKeyState(VK_RSHIFT) & 0x8000)) {
     1.5  						wParam = VK_RSHIFT;
     1.6  					} else {
     1.7 -						/* Probably a key repeat */
     1.8 -						return(0);
     1.9 +						/* Win9x */
    1.10 +						int sc = HIWORD(lParam) & 0xFF;
    1.11 +
    1.12 +						if (sc == 0x2A)
    1.13 +							wParam = VK_LSHIFT;
    1.14 +						else
    1.15 +						if (sc == 0x36)
    1.16 +							wParam = VK_RSHIFT;
    1.17 +						else
    1.18 +							wParam = VK_LSHIFT;
    1.19  					}
    1.20  					}
    1.21  					break;
    1.22 @@ -185,8 +193,16 @@
    1.23  					} else if (state[SDLK_RSHIFT] == SDL_PRESSED && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
    1.24  						wParam = VK_RSHIFT;
    1.25  					} else {
    1.26 -						/* Probably a key repeat */
    1.27 -						return(0);
    1.28 +						/* Win9x */
    1.29 +						int sc = HIWORD(lParam) & 0xFF;
    1.30 +
    1.31 +						if (sc == 0x2A)
    1.32 +							wParam = VK_LSHIFT;
    1.33 +						else
    1.34 +						if (sc == 0x36)
    1.35 +							wParam = VK_RSHIFT;
    1.36 +						else
    1.37 +							wParam = VK_LSHIFT;
    1.38  					}
    1.39  					}
    1.40  					break;
    1.41 @@ -252,9 +268,22 @@
    1.42  	}
    1.43  }
    1.44  
    1.45 +static HKL hLayoutUS = NULL;
    1.46 +
    1.47  void DIB_InitOSKeymap(_THIS)
    1.48  {
    1.49 -	int i;
    1.50 +	int	i;
    1.51 +	char	current_layout[256];
    1.52 +
    1.53 +	GetKeyboardLayoutName(current_layout);
    1.54 +	//printf("Initial Keyboard Layout Name: '%s'\n", current_layout);
    1.55 +
    1.56 +	hLayoutUS = LoadKeyboardLayout("00000409", KLF_NOTELLSHELL);
    1.57 +	if (!hLayoutUS) {
    1.58 +		//printf("Failed to load US keyboard layout. Using current.\n");
    1.59 +		hLayoutUS = GetKeyboardLayout(0);
    1.60 +	}
    1.61 +	LoadKeyboardLayout(current_layout, KLF_ACTIVATE);
    1.62  
    1.63  	/* Map the VK keysyms */
    1.64  	for ( i=0; i<SDL_arraysize(VK_keymap); ++i )
    1.65 @@ -381,11 +410,53 @@
    1.66  	VK_keymap[VK_APPS] = SDLK_MENU;
    1.67  }
    1.68  
    1.69 +#define EXTKEYPAD(keypad) ((scancode & 0x100)?(mvke):(keypad))
    1.70 +
    1.71 +static int SDL_MapVirtualKey(int scancode, int vkey)
    1.72 +{
    1.73 +	int	mvke  = MapVirtualKeyEx(scancode & 0xFF, 1, hLayoutUS);
    1.74 +
    1.75 +	switch(vkey) {
    1.76 +		/* These are always correct */
    1.77 +		case VK_DIVIDE:
    1.78 +		case VK_MULTIPLY:
    1.79 +		case VK_SUBTRACT:
    1.80 +		case VK_ADD:
    1.81 +		case VK_LWIN:
    1.82 +		case VK_RWIN:
    1.83 +		case VK_APPS:
    1.84 +		/* These are already handled */
    1.85 +		case VK_LCONTROL:
    1.86 +		case VK_RCONTROL:
    1.87 +		case VK_LSHIFT:
    1.88 +		case VK_RSHIFT:
    1.89 +		case VK_LMENU:
    1.90 +		case VK_RMENU:
    1.91 +		case VK_SNAPSHOT:
    1.92 +		case VK_PAUSE:
    1.93 +			return vkey;
    1.94 +	}	
    1.95 +	switch(mvke) {
    1.96 +		/* Distinguish between keypad and extended keys */
    1.97 +		case VK_INSERT: return EXTKEYPAD(VK_NUMPAD0);
    1.98 +		case VK_DELETE: return EXTKEYPAD(VK_DECIMAL);
    1.99 +		case VK_END:    return EXTKEYPAD(VK_NUMPAD1);
   1.100 +		case VK_DOWN:   return EXTKEYPAD(VK_NUMPAD2);
   1.101 +		case VK_NEXT:   return EXTKEYPAD(VK_NUMPAD3);
   1.102 +		case VK_LEFT:   return EXTKEYPAD(VK_NUMPAD4);
   1.103 +		case VK_CLEAR:  return EXTKEYPAD(VK_NUMPAD5);
   1.104 +		case VK_RIGHT:  return EXTKEYPAD(VK_NUMPAD6);
   1.105 +		case VK_HOME:   return EXTKEYPAD(VK_NUMPAD7);
   1.106 +		case VK_UP:     return EXTKEYPAD(VK_NUMPAD8);
   1.107 +		case VK_PRIOR:  return EXTKEYPAD(VK_NUMPAD9);
   1.108 +	}
   1.109 +	return mvke?mvke:vkey;
   1.110 +}
   1.111 +
   1.112  static SDL_keysym *TranslateKey(WPARAM vkey, UINT scancode, SDL_keysym *keysym, int pressed)
   1.113  {
   1.114  	/* Set the keysym information */
   1.115  	keysym->scancode = (unsigned char) scancode;
   1.116 -	keysym->sym = VK_keymap[vkey];
   1.117  	keysym->mod = KMOD_NONE;
   1.118  	keysym->unicode = 0;
   1.119  	if ( pressed && SDL_TranslateUNICODE ) {
   1.120 @@ -403,6 +474,30 @@
   1.121  		}
   1.122  #endif /* NO_GETKEYBOARDSTATE */
   1.123  	}
   1.124 +
   1.125 +	if ((vkey == VK_RETURN) && (scancode & 0x100)) {
   1.126 +		/* No VK_ code for the keypad enter key */
   1.127 +		keysym->sym = SDLK_KP_ENTER;
   1.128 +	}
   1.129 +	else {
   1.130 +		keysym->sym = VK_keymap[SDL_MapVirtualKey(scancode, vkey)];
   1.131 +	}
   1.132 +
   1.133 +#if 0
   1.134 +	{
   1.135 +		HKL     hLayoutCurrent = GetKeyboardLayout(0);
   1.136 +		int     sc = scancode & 0xFF;
   1.137 +
   1.138 +		printf("SYM:%d, VK:0x%02X, SC:0x%04X, US:(1:0x%02X, 3:0x%02X), "
   1.139 +			"Current:(1:0x%02X, 3:0x%02X)\n",
   1.140 +			keysym->sym, vkey, scancode,
   1.141 +			MapVirtualKeyEx(sc, 1, hLayoutUS),
   1.142 +			MapVirtualKeyEx(sc, 3, hLayoutUS),
   1.143 +			MapVirtualKeyEx(sc, 1, hLayoutCurrent),
   1.144 +			MapVirtualKeyEx(sc, 3, hLayoutCurrent)
   1.145 +		);
   1.146 +	}
   1.147 +#endif
   1.148  	return(keysym);
   1.149  }
   1.150