src/video/windows/SDL_windowskeyboard.c
changeset 6938 b272d47f70a7
parent 6926 166712f45009
child 7191 75360622e65f
equal deleted inserted replaced
6937:6a0e4dc3a489 6938:b272d47f70a7
    46 #ifndef MAPVK_VK_TO_CHAR
    46 #ifndef MAPVK_VK_TO_CHAR
    47 #define MAPVK_VK_TO_CHAR    2
    47 #define MAPVK_VK_TO_CHAR    2
    48 #endif
    48 #endif
    49 
    49 
    50 /* Alphabetic scancodes for PC keyboards */
    50 /* Alphabetic scancodes for PC keyboards */
    51 BYTE alpha_scancodes[26] = {
       
    52     30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38, 50, 49, 24,
       
    53     25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44
       
    54 };
       
    55 
       
    56 BYTE keypad_scancodes[10] = {
       
    57     82, 79, 80, 81, 75, 76, 77, 71, 72, 73
       
    58 };
       
    59 
       
    60 void
    51 void
    61 WIN_InitKeyboard(_THIS)
    52 WIN_InitKeyboard(_THIS)
    62 {
    53 {
    63     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    54     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    64     int i;
       
    65 
       
    66     /* Make sure the alpha scancodes are correct.  T isn't usually remapped */
       
    67     if (MapVirtualKey('T', MAPVK_VK_TO_VSC) != alpha_scancodes['T' - 'A']) {
       
    68 #if 0
       
    69         printf
       
    70             ("Fixing alpha scancode map, assuming US QWERTY layout!\nPlease send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
       
    71 #endif
       
    72         for (i = 0; i < SDL_arraysize(alpha_scancodes); ++i) {
       
    73             alpha_scancodes[i] = MapVirtualKey('A' + i, MAPVK_VK_TO_VSC);
       
    74 #if 0
       
    75             printf("%d = %d\n", i, alpha_scancodes[i]);
       
    76 #endif
       
    77         }
       
    78     }
       
    79     if (MapVirtualKey(VK_NUMPAD0, MAPVK_VK_TO_VSC) != keypad_scancodes[0]) {
       
    80 #if 0
       
    81         printf
       
    82             ("Fixing keypad scancode map!\nPlease send the following 10 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware.\n");
       
    83 #endif
       
    84         for (i = 0; i < SDL_arraysize(keypad_scancodes); ++i) {
       
    85             keypad_scancodes[i] =
       
    86                 MapVirtualKey(VK_NUMPAD0 + i, MAPVK_VK_TO_VSC);
       
    87 #if 0
       
    88             printf("%d = %d\n", i, keypad_scancodes[i]);
       
    89 #endif
       
    90         }
       
    91     }
       
    92 
       
    93 	// windows scancode to SDL scancode table
       
    94     data->key_layout = windows_scancode_table;
       
    95 
    55 
    96     data->ime_com_initialized = SDL_FALSE;
    56     data->ime_com_initialized = SDL_FALSE;
    97     data->ime_threadmgr = 0;
    57     data->ime_threadmgr = 0;
    98     data->ime_initialized = SDL_FALSE;
    58     data->ime_initialized = SDL_FALSE;
    99     data->ime_enabled = SDL_FALSE;
    59     data->ime_enabled = SDL_FALSE;
   149 {
   109 {
   150     int i;
   110     int i;
   151     SDL_Scancode scancode;
   111     SDL_Scancode scancode;
   152     SDL_Keycode keymap[SDL_NUM_SCANCODES];
   112     SDL_Keycode keymap[SDL_NUM_SCANCODES];
   153 
   113 
   154 	for (i = 0; i < SDL_arraysize(keymap); ++i)
   114     SDL_GetDefaultKeymap(keymap);
   155 	{
       
   156 		keymap[i] = SDL_SCANCODE_TO_KEYCODE( i );
       
   157 	}
       
   158 
   115 
   159     for (i = 0; i < SDL_arraysize(windows_scancode_table); i++) {
   116     for (i = 0; i < SDL_arraysize(windows_scancode_table); i++) {
   160 		int vk;
   117         int vk;
   161         /* Make sure this scancode is a valid character scancode */
   118         /* Make sure this scancode is a valid character scancode */
   162         scancode = windows_scancode_table[i];
   119         scancode = windows_scancode_table[i];
   163         if (scancode == SDL_SCANCODE_UNKNOWN ) {
   120         if (scancode == SDL_SCANCODE_UNKNOWN ) {
   164             continue;
   121             continue;
   165         }
   122         }
   166 		/* Don't allow the number keys right above the qwerty row to translate or the top left key (grave/backquote) */
   123 
   167 		/* not mapping numbers fixes the AZERTY layout (french) causing non-shifted number to appear by default */
   124         /* If this key is one of the non-mappable keys, ignore it */
   168 		if ( scancode == SDL_SCANCODE_GRAVE ) {
   125         /* Don't allow the number keys right above the qwerty row to translate or the top left key (grave/backquote) */
   169 			keymap[scancode]  = SDLK_BACKQUOTE;
   126         /* Not mapping numbers fixes the French layout, giving numeric keycodes for the number keys, which is the expected behavior */
   170 			continue;
   127         if ((keymap[scancode] & SDLK_SCANCODE_MASK) ||
   171 		}
   128             scancode == SDL_SCANCODE_GRAVE ||
   172 		if ( scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0 ) {
   129             (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0) ) {
   173 			 keymap[scancode] = SDLK_1 + ( scancode - SDL_SCANCODE_1 );
   130             continue;
   174 			continue;
   131         }
   175 		}
   132 
   176 
   133         vk =  MapVirtualKey(i, MAPVK_VSC_TO_VK);
   177 		vk =  MapVirtualKey(i, MAPVK_VSC_TO_VK);
   134         if ( vk ) {
   178 		if ( vk ) {
   135             int ch = (MapVirtualKey( vk, MAPVK_VK_TO_CHAR ) & 0x7FFF);
   179 			int ch;
   136             if ( ch ) {
   180 			ch = (MapVirtualKey( vk, MAPVK_VK_TO_CHAR ) & 0x7FFF);
   137                 if ( ch >= 'A' && ch <= 'Z' ) {
   181 			 if ( ch )
   138                     keymap[scancode] =  SDLK_a + ( ch - 'A' );
   182 			 {
   139                 } else {
   183 				 if ( ch >= 'A' && ch <= 'Z' )
   140                     keymap[scancode] = ch;
   184 					keymap[scancode] =  SDLK_a + ( ch - 'A' );
   141                 }
   185 				 else
   142             }
   186 					 keymap[scancode] = ch;
   143         }
   187 			 }
       
   188 
       
   189 		}
       
   190     }
   144     }
   191 
   145 
   192     SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
   146     SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
   193 }
   147 }
   194 
   148