2001-04-26 16:50:19 +00:00
/*
SDL - Simple DirectMedia Layer
2006-02-01 06:32:25 +00:00
Copyright ( C ) 1997 - 2006 Sam Lantinga
2001-04-26 16:50:19 +00:00
This library is free software ; you can redistribute it and / or
2006-02-01 06:32:25 +00:00
modify it under the terms of the GNU Lesser General Public
2001-04-26 16:50:19 +00:00
License as published by the Free Software Foundation ; either
2006-02-01 06:32:25 +00:00
version 2.1 of the License , or ( at your option ) any later version .
2001-04-26 16:50:19 +00:00
This library is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
2006-02-01 06:32:25 +00:00
Lesser General Public License for more details .
2001-04-26 16:50:19 +00:00
2006-02-01 06:32:25 +00:00
You should have received a copy of the GNU Lesser General Public
License along with this library ; if not , write to the Free Software
Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 USA
2001-04-26 16:50:19 +00:00
Sam Lantinga
2001-12-14 12:38:15 +00:00
slouken @ libsdl . org
2001-04-26 16:50:19 +00:00
*/
2006-02-21 08:46:50 +00:00
# include "SDL_config.h"
2001-04-26 16:50:19 +00:00
2006-07-10 21:04:37 +00:00
# include "SDL_win32video.h"
2001-04-26 16:50:19 +00:00
2006-07-10 21:04:37 +00:00
# include "../../events/SDL_keyboard_c.h"
2008-02-08 08:35:49 +00:00
# include "../../events/scancodes_win32.h"
2001-04-26 16:50:19 +00:00
2008-02-09 22:28:27 +00:00
# ifndef MAPVK_VK_TO_VSC
# define MAPVK_VK_TO_VSC 0
# endif
# ifndef MAPVK_VSC_TO_VK
# define MAPVK_VSC_TO_VK 1
# endif
# ifndef MAPVK_VK_TO_CHAR
# define MAPVK_VK_TO_CHAR 2
# endif
/* Alphabetic scancodes for PC keyboards */
BYTE alpha_scancodes [ 26 ] = {
30 , 48 , 46 , 32 , 18 , 33 , 34 , 35 , 23 , 36 , 37 , 38 , 50 , 49 , 24 ,
25 , 16 , 19 , 31 , 20 , 22 , 47 , 17 , 45 , 21 , 44
} ;
2006-07-10 21:04:37 +00:00
void
WIN_InitKeyboard ( _THIS )
{
SDL_VideoData * data = ( SDL_VideoData * ) _this - > driverdata ;
SDL_Keyboard keyboard ;
2008-02-09 22:28:27 +00:00
int i ;
/* Make sure the alpha scancodes are correct. T isn't usually remapped */
if ( MapVirtualKey ( ' T ' , MAPVK_VK_TO_VSC ) ! = alpha_scancodes [ ' T ' - ' A ' ] ) {
printf ( " Fixing alpha scancode map, assuming US QWERTY layout! \n Please send the following 26 lines of output to the SDL mailing list <sdl@libsdl.org>, including a description of your keyboard hardware. \n " ) ;
for ( i = 0 ; i < SDL_arraysize ( alpha_scancodes ) ; + + i ) {
alpha_scancodes [ i ] = MapVirtualKey ( ' A ' + i , MAPVK_VK_TO_VSC ) ;
printf ( " %d = %d \n " , i , alpha_scancodes [ i ] ) ;
}
}
2001-04-26 16:50:19 +00:00
2008-02-08 08:35:49 +00:00
data - > key_layout = win32_scancode_table ;
2006-07-10 21:04:37 +00:00
SDL_zero ( keyboard ) ;
data - > keyboard = SDL_AddKeyboard ( & keyboard , - 1 ) ;
2008-02-09 22:28:27 +00:00
WIN_UpdateKeymap ( data - > keyboard ) ;
2008-02-08 08:35:49 +00:00
SDL_SetScancodeName ( SDL_SCANCODE_APPLICATION , " Menu " ) ;
SDL_SetScancodeName ( SDL_SCANCODE_LGUI , " Left Windows " ) ;
SDL_SetScancodeName ( SDL_SCANCODE_RGUI , " Right Windows " ) ;
}
void
2008-02-09 22:28:27 +00:00
WIN_UpdateKeymap ( int keyboard )
2008-02-08 08:35:49 +00:00
{
int i ;
SDL_scancode scancode ;
SDLKey keymap [ SDL_NUM_SCANCODES ] ;
SDL_GetDefaultKeymap ( keymap ) ;
for ( i = 0 ; i < SDL_arraysize ( win32_scancode_table ) ; i + + ) {
/* Make sure this scancode is a valid character scancode */
scancode = win32_scancode_table [ i ] ;
if ( scancode = = SDL_SCANCODE_UNKNOWN | |
( keymap [ scancode ] & SDLK_SCANCODE_MASK ) ) {
continue ;
}
2008-02-09 22:28:27 +00:00
/* Alphabetic keys are handled specially, since Windows remaps them */
if ( i > = ' A ' & & i < = ' Z ' ) {
BYTE vsc = alpha_scancodes [ i - ' A ' ] ;
keymap [ scancode ] = MapVirtualKey ( vsc , MAPVK_VSC_TO_VK ) + 0x20 ;
} else {
keymap [ scancode ] = ( MapVirtualKey ( i , MAPVK_VK_TO_CHAR ) & 0x7FFF ) ;
}
2008-02-08 08:35:49 +00:00
}
2008-02-09 22:28:27 +00:00
SDL_SetKeymap ( keyboard , 0 , keymap , SDL_NUM_SCANCODES ) ;
2006-07-10 21:04:37 +00:00
}
void
WIN_QuitKeyboard ( _THIS )
{
SDL_VideoData * data = ( SDL_VideoData * ) _this - > driverdata ;
SDL_DelKeyboard ( data - > keyboard ) ;
}
/* vi: set ts=4 sw=4 expandtab: */