src/video/svga/SDL_svgaevents.c
author Ozkan Sezer <sezeroz@gmail.com>
Sun, 14 Oct 2018 15:25:04 +0300
branchSDL-1.2
changeset 12325 c4f2eeda176f
parent 12053 edddd89f910d
permissions -rw-r--r--
remove symlink for libSDL-1.0.so.0 from the rpm spec file.

also fix a changelog date.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@6137
     3
    Copyright (C) 1997-2012 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@0
    23
slouken@0
    24
/* Handle the event stream, converting X11 events into SDL events */
slouken@0
    25
sezeroz@12053
    26
#include <sys/types.h>
sezeroz@12053
    27
#include <sys/ioctl.h>
sezeroz@12053
    28
slouken@0
    29
#include <vga.h>
slouken@0
    30
#include <vgamouse.h>
slouken@0
    31
#include <vgakeyboard.h>
slouken@1402
    32
#if defined(__LINUX__)
slouken@0
    33
#include <linux/kd.h>
slouken@0
    34
#include <linux/keyboard.h>
slouken@1402
    35
#elif defined(__FREEBSD__)
slouken@0
    36
#include <sys/kbio.h>
slouken@0
    37
#else
slouken@0
    38
#error You must choose your operating system here
slouken@0
    39
#endif
slouken@0
    40
slouken@1361
    41
#include "../../events/SDL_sysevents.h"
slouken@1361
    42
#include "../../events/SDL_events_c.h"
slouken@0
    43
#include "SDL_svgavideo.h"
slouken@0
    44
#include "SDL_svgaevents_c.h"
slouken@0
    45
slouken@0
    46
/* The translation tables from a console scancode to a SDL keysym */
slouken@0
    47
#if defined(linux)
slouken@0
    48
#define NUM_VGAKEYMAPS	(1<<KG_CAPSSHIFT)
slouken@0
    49
static Uint16 vga_keymap[NUM_VGAKEYMAPS][NR_KEYS];
slouken@1402
    50
#elif defined(__FREEBSD__)
slouken@0
    51
/* FIXME: Free the keymap when we shut down the video mode */
slouken@0
    52
static keymap_t *vga_keymap = NULL;
slouken@0
    53
#else
slouken@0
    54
#error You must choose your operating system here
slouken@0
    55
#endif
slouken@0
    56
static SDLKey keymap[128];
slouken@0
    57
static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym);
slouken@0
    58
slouken@0
    59
/* Ugh, we have to duplicate the kernel's keysym mapping code...
slouken@0
    60
   Oh, it's not so bad. :-)
slouken@0
    61
slouken@0
    62
   FIXME: Add keyboard LED handling code
slouken@0
    63
 */
slouken@0
    64
#if defined(linux)
slouken@0
    65
int SVGA_initkeymaps(int fd)
slouken@0
    66
{
slouken@0
    67
	struct kbentry entry;
slouken@0
    68
	int map, i;
slouken@0
    69
slouken@0
    70
	/* Load all the keysym mappings */
slouken@0
    71
	for ( map=0; map<NUM_VGAKEYMAPS; ++map ) {
slouken@1336
    72
		SDL_memset(vga_keymap[map], 0, NR_KEYS*sizeof(Uint16));
slouken@0
    73
		for ( i=0; i<NR_KEYS; ++i ) {
slouken@0
    74
			entry.kb_table = map;
slouken@0
    75
			entry.kb_index = i;
slouken@0
    76
			if ( ioctl(fd, KDGKBENT, &entry) == 0 ) {
slouken@0
    77
				/* The "Enter" key is a special case */
slouken@0
    78
				if ( entry.kb_value == K_ENTER ) {
slouken@0
    79
					entry.kb_value = K(KT_ASCII,13);
slouken@0
    80
				}
slouken@0
    81
				/* Handle numpad specially as well */
slouken@0
    82
				if ( KTYP(entry.kb_value) == KT_PAD ) {
slouken@0
    83
				    switch ( entry.kb_value ) {
slouken@0
    84
					case K_P0:
slouken@0
    85
					case K_P1:
slouken@0
    86
					case K_P2:
slouken@0
    87
					case K_P3:
slouken@0
    88
					case K_P4:
slouken@0
    89
					case K_P5:
slouken@0
    90
					case K_P6:
slouken@0
    91
					case K_P7:
slouken@0
    92
					case K_P8:
slouken@0
    93
					case K_P9:
slouken@0
    94
					    vga_keymap[map][i]=entry.kb_value;
slouken@0
    95
					    vga_keymap[map][i]+= '0';
slouken@0
    96
					    break;
slouken@0
    97
                                        case K_PPLUS:
slouken@0
    98
					    vga_keymap[map][i]=K(KT_ASCII,'+');
slouken@0
    99
					    break;
slouken@0
   100
                                        case K_PMINUS:
slouken@0
   101
					    vga_keymap[map][i]=K(KT_ASCII,'-');
slouken@0
   102
					    break;
slouken@0
   103
                                        case K_PSTAR:
slouken@0
   104
					    vga_keymap[map][i]=K(KT_ASCII,'*');
slouken@0
   105
					    break;
slouken@0
   106
                                        case K_PSLASH:
slouken@0
   107
					    vga_keymap[map][i]=K(KT_ASCII,'/');
slouken@0
   108
					    break;
slouken@0
   109
                                        case K_PENTER:
slouken@0
   110
					    vga_keymap[map][i]=K(KT_ASCII,'\r');
slouken@0
   111
					    break;
slouken@0
   112
                                        case K_PCOMMA:
slouken@0
   113
					    vga_keymap[map][i]=K(KT_ASCII,',');
slouken@0
   114
					    break;
slouken@0
   115
                                        case K_PDOT:
slouken@0
   116
					    vga_keymap[map][i]=K(KT_ASCII,'.');
slouken@0
   117
					    break;
slouken@0
   118
					default:
slouken@0
   119
					    break;
slouken@0
   120
				    }
slouken@0
   121
				}
slouken@0
   122
				/* Do the normal key translation */
slouken@0
   123
				if ( (KTYP(entry.kb_value) == KT_LATIN) ||
slouken@0
   124
				     (KTYP(entry.kb_value) == KT_ASCII) ||
slouken@0
   125
				     (KTYP(entry.kb_value) == KT_LETTER) ) {
slouken@0
   126
					vga_keymap[map][i] = entry.kb_value;
slouken@0
   127
				}
slouken@0
   128
			}
slouken@0
   129
		}
slouken@0
   130
	}
slouken@0
   131
	return(0);
slouken@0
   132
}
slouken@1402
   133
#elif defined(__FREEBSD__)
slouken@0
   134
int SVGA_initkeymaps(int fd)
slouken@0
   135
{
slouken@1336
   136
	vga_keymap = SDL_malloc(sizeof(keymap_t));
slouken@0
   137
	if ( ! vga_keymap ) {
slouken@0
   138
		SDL_OutOfMemory();
slouken@0
   139
		return(-1);
slouken@0
   140
	}
slouken@0
   141
	if (ioctl(fd, GIO_KEYMAP, vga_keymap) == -1) {
slouken@1336
   142
		SDL_free(vga_keymap);
slouken@0
   143
		vga_keymap = NULL;
slouken@0
   144
		SDL_SetError("Unable to get keyboard map");
slouken@0
   145
		return(-1);
slouken@0
   146
	}
slouken@0
   147
	return(0);
slouken@0
   148
}
slouken@0
   149
#else
slouken@0
   150
#error You must choose your operating system here
slouken@0
   151
#endif
slouken@0
   152
slouken@0
   153
int posted = 0;
slouken@0
   154
slouken@0
   155
void SVGA_mousecallback(int button, int dx, int dy,
slouken@0
   156
                          int u1,int u2,int u3, int u4)
slouken@0
   157
{
slouken@0
   158
	if ( dx || dy ) {
slouken@0
   159
		posted += SDL_PrivateMouseMotion(0, 1, dx, dy);
slouken@0
   160
	}
slouken@0
   161
	if ( button & MOUSE_LEFTBUTTON ) {
slouken@0
   162
		if ( !(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1)) ) {
slouken@0
   163
			posted += SDL_PrivateMouseButton(SDL_PRESSED, 1, 0, 0);
slouken@0
   164
		}
slouken@0
   165
	} else {
slouken@0
   166
		if ( (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1)) ) {
slouken@0
   167
			posted += SDL_PrivateMouseButton(SDL_RELEASED, 1, 0, 0);
slouken@0
   168
		}
slouken@0
   169
	}
slouken@0
   170
	if ( button & MOUSE_MIDDLEBUTTON ) {
slouken@0
   171
		if ( !(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(2)) ) {
slouken@0
   172
			posted += SDL_PrivateMouseButton(SDL_PRESSED, 2, 0, 0);
slouken@0
   173
		}
slouken@0
   174
	} else {
slouken@0
   175
		if ( (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(2)) ) {
slouken@0
   176
			posted += SDL_PrivateMouseButton(SDL_RELEASED, 2, 0, 0);
slouken@0
   177
		}
slouken@0
   178
	}
slouken@0
   179
	if ( button & MOUSE_RIGHTBUTTON ) {
slouken@0
   180
		if ( !(SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3)) ) {
slouken@0
   181
			posted += SDL_PrivateMouseButton(SDL_PRESSED, 3, 0, 0);
slouken@0
   182
		}
slouken@0
   183
	} else {
slouken@0
   184
		if ( (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(3)) ) {
slouken@0
   185
			posted += SDL_PrivateMouseButton(SDL_RELEASED, 3, 0, 0);
slouken@0
   186
		}
slouken@0
   187
	}
slouken@0
   188
}
slouken@0
   189
slouken@0
   190
void SVGA_keyboardcallback(int scancode, int pressed)
slouken@0
   191
{
slouken@0
   192
	SDL_keysym keysym;
slouken@0
   193
slouken@0
   194
	if ( pressed ) {
slouken@0
   195
		posted += SDL_PrivateKeyboard(SDL_PRESSED,
slouken@0
   196
			    TranslateKey(scancode, &keysym));
slouken@0
   197
	} else {
slouken@0
   198
		posted += SDL_PrivateKeyboard(SDL_RELEASED,
slouken@0
   199
			    TranslateKey(scancode, &keysym));
slouken@0
   200
	}
slouken@0
   201
}
slouken@0
   202
slouken@0
   203
void SVGA_PumpEvents(_THIS)
slouken@0
   204
{
slouken@0
   205
	do {
slouken@0
   206
		posted = 0;
slouken@0
   207
		mouse_update();
slouken@0
   208
		keyboard_update();
slouken@0
   209
	} while ( posted );
slouken@0
   210
}
slouken@0
   211
slouken@0
   212
void SVGA_InitOSKeymap(_THIS)
slouken@0
   213
{
slouken@0
   214
	int i;
slouken@0
   215
slouken@0
   216
	/* Initialize the BeOS key translation table */
slouken@1379
   217
	for ( i=0; i<SDL_arraysize(keymap); ++i )
slouken@0
   218
		keymap[i] = SDLK_UNKNOWN;
slouken@0
   219
slouken@0
   220
	keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
slouken@0
   221
	keymap[SCANCODE_1] = SDLK_1;
slouken@0
   222
	keymap[SCANCODE_2] = SDLK_2;
slouken@0
   223
	keymap[SCANCODE_3] = SDLK_3;
slouken@0
   224
	keymap[SCANCODE_4] = SDLK_4;
slouken@0
   225
	keymap[SCANCODE_5] = SDLK_5;
slouken@0
   226
	keymap[SCANCODE_6] = SDLK_6;
slouken@0
   227
	keymap[SCANCODE_7] = SDLK_7;
slouken@0
   228
	keymap[SCANCODE_8] = SDLK_8;
slouken@0
   229
	keymap[SCANCODE_9] = SDLK_9;
slouken@0
   230
	keymap[SCANCODE_0] = SDLK_0;
slouken@0
   231
	keymap[SCANCODE_MINUS] = SDLK_MINUS;
slouken@0
   232
	keymap[SCANCODE_EQUAL] = SDLK_EQUALS;
slouken@0
   233
	keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
slouken@0
   234
	keymap[SCANCODE_TAB] = SDLK_TAB;
slouken@0
   235
	keymap[SCANCODE_Q] = SDLK_q;
slouken@0
   236
	keymap[SCANCODE_W] = SDLK_w;
slouken@0
   237
	keymap[SCANCODE_E] = SDLK_e;
slouken@0
   238
	keymap[SCANCODE_R] = SDLK_r;
slouken@0
   239
	keymap[SCANCODE_T] = SDLK_t;
slouken@0
   240
	keymap[SCANCODE_Y] = SDLK_y;
slouken@0
   241
	keymap[SCANCODE_U] = SDLK_u;
slouken@0
   242
	keymap[SCANCODE_I] = SDLK_i;
slouken@0
   243
	keymap[SCANCODE_O] = SDLK_o;
slouken@0
   244
	keymap[SCANCODE_P] = SDLK_p;
slouken@0
   245
	keymap[SCANCODE_BRACKET_LEFT] = SDLK_LEFTBRACKET;
slouken@0
   246
	keymap[SCANCODE_BRACKET_RIGHT] = SDLK_RIGHTBRACKET;
slouken@0
   247
	keymap[SCANCODE_ENTER] = SDLK_RETURN;
slouken@0
   248
	keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
slouken@0
   249
	keymap[SCANCODE_A] = SDLK_a;
slouken@0
   250
	keymap[SCANCODE_S] = SDLK_s;
slouken@0
   251
	keymap[SCANCODE_D] = SDLK_d;
slouken@0
   252
	keymap[SCANCODE_F] = SDLK_f;
slouken@0
   253
	keymap[SCANCODE_G] = SDLK_g;
slouken@0
   254
	keymap[SCANCODE_H] = SDLK_h;
slouken@0
   255
	keymap[SCANCODE_J] = SDLK_j;
slouken@0
   256
	keymap[SCANCODE_K] = SDLK_k;
slouken@0
   257
	keymap[SCANCODE_L] = SDLK_l;
slouken@0
   258
	keymap[SCANCODE_SEMICOLON] = SDLK_SEMICOLON;
slouken@0
   259
	keymap[SCANCODE_APOSTROPHE] = SDLK_QUOTE;
slouken@0
   260
	keymap[SCANCODE_GRAVE] = SDLK_BACKQUOTE;
slouken@0
   261
	keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
slouken@0
   262
	keymap[SCANCODE_BACKSLASH] = SDLK_BACKSLASH;
slouken@0
   263
	keymap[SCANCODE_Z] = SDLK_z;
slouken@0
   264
	keymap[SCANCODE_X] = SDLK_x;
slouken@0
   265
	keymap[SCANCODE_C] = SDLK_c;
slouken@0
   266
	keymap[SCANCODE_V] = SDLK_v;
slouken@0
   267
	keymap[SCANCODE_B] = SDLK_b;
slouken@0
   268
	keymap[SCANCODE_N] = SDLK_n;
slouken@0
   269
	keymap[SCANCODE_M] = SDLK_m;
slouken@0
   270
	keymap[SCANCODE_COMMA] = SDLK_COMMA;
slouken@0
   271
	keymap[SCANCODE_PERIOD] = SDLK_PERIOD;
slouken@0
   272
	keymap[SCANCODE_SLASH] = SDLK_SLASH;
slouken@0
   273
	keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
slouken@0
   274
	keymap[SCANCODE_KEYPADMULTIPLY] = SDLK_KP_MULTIPLY;
slouken@0
   275
	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
slouken@0
   276
	keymap[SCANCODE_SPACE] = SDLK_SPACE;
slouken@0
   277
	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
slouken@0
   278
	keymap[SCANCODE_F1] = SDLK_F1;
slouken@0
   279
	keymap[SCANCODE_F2] = SDLK_F2;
slouken@0
   280
	keymap[SCANCODE_F3] = SDLK_F3;
slouken@0
   281
	keymap[SCANCODE_F4] = SDLK_F4;
slouken@0
   282
	keymap[SCANCODE_F5] = SDLK_F5;
slouken@0
   283
	keymap[SCANCODE_F6] = SDLK_F6;
slouken@0
   284
	keymap[SCANCODE_F7] = SDLK_F7;
slouken@0
   285
	keymap[SCANCODE_F8] = SDLK_F8;
slouken@0
   286
	keymap[SCANCODE_F9] = SDLK_F9;
slouken@0
   287
	keymap[SCANCODE_F10] = SDLK_F10;
slouken@0
   288
	keymap[SCANCODE_NUMLOCK] = SDLK_NUMLOCK;
slouken@0
   289
	keymap[SCANCODE_SCROLLLOCK] = SDLK_SCROLLOCK;
slouken@0
   290
	keymap[SCANCODE_KEYPAD7] = SDLK_KP7;
slouken@0
   291
	keymap[SCANCODE_CURSORUPLEFT] = SDLK_KP7;
slouken@0
   292
	keymap[SCANCODE_KEYPAD8] = SDLK_KP8;
slouken@0
   293
	keymap[SCANCODE_CURSORUP] = SDLK_KP8;
slouken@0
   294
	keymap[SCANCODE_KEYPAD9] = SDLK_KP9;
slouken@0
   295
	keymap[SCANCODE_CURSORUPRIGHT] = SDLK_KP9;
slouken@0
   296
	keymap[SCANCODE_KEYPADMINUS] = SDLK_KP_MINUS;
slouken@0
   297
	keymap[SCANCODE_KEYPAD4] = SDLK_KP4;
slouken@0
   298
	keymap[SCANCODE_CURSORLEFT] = SDLK_KP4;
slouken@0
   299
	keymap[SCANCODE_KEYPAD5] = SDLK_KP5;
slouken@0
   300
	keymap[SCANCODE_KEYPAD6] = SDLK_KP6;
slouken@0
   301
	keymap[SCANCODE_CURSORRIGHT] = SDLK_KP6;
slouken@0
   302
	keymap[SCANCODE_KEYPADPLUS] = SDLK_KP_PLUS;
slouken@0
   303
	keymap[SCANCODE_KEYPAD1] = SDLK_KP1;
slouken@0
   304
	keymap[SCANCODE_CURSORDOWNLEFT] = SDLK_KP1;
slouken@0
   305
	keymap[SCANCODE_KEYPAD2] = SDLK_KP2;
slouken@0
   306
	keymap[SCANCODE_CURSORDOWN] = SDLK_KP2;
slouken@0
   307
	keymap[SCANCODE_KEYPAD3] = SDLK_KP3;
slouken@0
   308
	keymap[SCANCODE_CURSORDOWNRIGHT] = SDLK_KP3;
slouken@0
   309
	keymap[SCANCODE_KEYPAD0] = SDLK_KP0;
slouken@0
   310
	keymap[SCANCODE_KEYPADPERIOD] = SDLK_KP_PERIOD;
slouken@0
   311
	keymap[SCANCODE_LESS] = SDLK_LESS;
slouken@0
   312
	keymap[SCANCODE_F11] = SDLK_F11;
slouken@0
   313
	keymap[SCANCODE_F12] = SDLK_F12;
slouken@0
   314
	keymap[SCANCODE_KEYPADENTER] = SDLK_KP_ENTER;
slouken@0
   315
	keymap[SCANCODE_RIGHTCONTROL] = SDLK_RCTRL;
slouken@0
   316
	keymap[SCANCODE_CONTROL] = SDLK_RCTRL;
slouken@0
   317
	keymap[SCANCODE_KEYPADDIVIDE] = SDLK_KP_DIVIDE;
slouken@0
   318
	keymap[SCANCODE_PRINTSCREEN] = SDLK_PRINT;
slouken@0
   319
	keymap[SCANCODE_RIGHTALT] = SDLK_RALT;
slouken@0
   320
	keymap[SCANCODE_BREAK] = SDLK_BREAK;
slouken@0
   321
	keymap[SCANCODE_BREAK_ALTERNATIVE] = SDLK_UNKNOWN;
slouken@0
   322
	keymap[SCANCODE_HOME] = SDLK_HOME;
slouken@0
   323
	keymap[SCANCODE_CURSORBLOCKUP] = SDLK_UP;
slouken@0
   324
	keymap[SCANCODE_PAGEUP] = SDLK_PAGEUP;
slouken@0
   325
	keymap[SCANCODE_CURSORBLOCKLEFT] = SDLK_LEFT;
slouken@0
   326
	keymap[SCANCODE_CURSORBLOCKRIGHT] = SDLK_RIGHT;
slouken@0
   327
	keymap[SCANCODE_END] = SDLK_END;
slouken@0
   328
	keymap[SCANCODE_CURSORBLOCKDOWN] = SDLK_DOWN;
slouken@0
   329
	keymap[SCANCODE_PAGEDOWN] = SDLK_PAGEDOWN;
slouken@0
   330
	keymap[SCANCODE_INSERT] = SDLK_INSERT;
slouken@0
   331
	keymap[SCANCODE_REMOVE] = SDLK_DELETE;
slouken@0
   332
	keymap[119] = SDLK_PAUSE;
slouken@0
   333
	keymap[SCANCODE_RIGHTWIN] = SDLK_RSUPER;
slouken@0
   334
	keymap[SCANCODE_LEFTWIN] = SDLK_LSUPER;
slouken@0
   335
	keymap[127] = SDLK_MENU;
slouken@0
   336
}
slouken@0
   337
slouken@0
   338
#if defined(linux)
slouken@0
   339
static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
slouken@0
   340
{
slouken@0
   341
	/* Set the keysym information */
slouken@0
   342
	keysym->scancode = scancode;
slouken@0
   343
	keysym->sym = keymap[scancode];
slouken@0
   344
	keysym->mod = KMOD_NONE;
slouken@0
   345
slouken@0
   346
	/* If UNICODE is on, get the UNICODE value for the key */
slouken@0
   347
	keysym->unicode = 0;
slouken@0
   348
	if ( SDL_TranslateUNICODE ) {
slouken@0
   349
		int map;
slouken@0
   350
		SDLMod modstate;
slouken@0
   351
slouken@0
   352
		modstate = SDL_GetModState();
slouken@0
   353
		map = 0;
slouken@0
   354
		if ( modstate & KMOD_SHIFT ) {
slouken@0
   355
			map |= (1<<KG_SHIFT);
slouken@0
   356
		}
slouken@0
   357
		if ( modstate & KMOD_CTRL ) {
slouken@0
   358
			map |= (1<<KG_CTRL);
slouken@0
   359
		}
slouken@0
   360
		if ( modstate & KMOD_ALT ) {
slouken@0
   361
			map |= (1<<KG_ALT);
slouken@0
   362
		}
slouken@0
   363
		if ( modstate & KMOD_MODE ) {
slouken@0
   364
			map |= (1<<KG_ALTGR);
slouken@0
   365
		}
slouken@0
   366
		if ( KTYP(vga_keymap[map][scancode]) == KT_LETTER ) {
slouken@0
   367
			if ( modstate & KMOD_CAPS ) {
slouken@0
   368
				map ^= (1<<KG_SHIFT);
slouken@0
   369
			}
slouken@0
   370
		}
slouken@0
   371
		if ( KTYP(vga_keymap[map][scancode]) == KT_PAD ) {
slouken@0
   372
			if ( modstate & KMOD_NUM ) {
slouken@0
   373
				keysym->unicode=KVAL(vga_keymap[map][scancode]);
slouken@0
   374
			}
slouken@0
   375
		} else {
slouken@0
   376
			keysym->unicode = KVAL(vga_keymap[map][scancode]);
slouken@0
   377
		}
slouken@0
   378
	}
slouken@0
   379
	return(keysym);
slouken@0
   380
}
slouken@1402
   381
#elif defined(__FREEBSD__)
slouken@0
   382
static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
slouken@0
   383
{
slouken@0
   384
	/* Set the keysym information */
slouken@0
   385
	keysym->scancode = scancode;
slouken@0
   386
	keysym->sym = keymap[scancode];
slouken@0
   387
	keysym->mod = KMOD_NONE;
slouken@0
   388
slouken@0
   389
	/* If UNICODE is on, get the UNICODE value for the key */
slouken@0
   390
	keysym->unicode = 0;
slouken@0
   391
	if ( SDL_TranslateUNICODE && vga_keymap ) {
slouken@0
   392
		int map;
slouken@0
   393
		SDLMod modstate;
slouken@0
   394
slouken@0
   395
		modstate = SDL_GetModState();
slouken@0
   396
		map = 0;
slouken@0
   397
		if ( modstate & KMOD_SHIFT ) {
slouken@0
   398
			map += 1;
slouken@0
   399
		}
slouken@0
   400
		if ( modstate & KMOD_CTRL ) {
slouken@0
   401
			map += 2;
slouken@0
   402
		}
slouken@0
   403
		if ( modstate & KMOD_ALT ) {
slouken@0
   404
			map += 4;
slouken@0
   405
		}
slouken@0
   406
		if ( !(vga_keymap->key[scancode].spcl & (0x80 >> map)) ) {
slouken@0
   407
			keysym->unicode = vga_keymap->key[scancode].map[map];
slouken@0
   408
		}
slouken@0
   409
slouken@0
   410
	}
slouken@0
   411
	return(keysym);
slouken@0
   412
}
slouken@0
   413
#else
slouken@0
   414
#error You must choose your operating system here
slouken@0
   415
#endif