*** empty log message ***
authorSam Lantinga
Sun, 23 Sep 2001 22:16:02 +0000
changeset 19849bf25403f5e
parent 197 ef78524e5f59
child 199 2ad0957f6265
*** empty log message ***
src/video/maccommon/SDL_macevents.c
     1.1 --- a/src/video/maccommon/SDL_macevents.c	Sun Sep 23 22:10:03 2001 +0000
     1.2 +++ b/src/video/maccommon/SDL_macevents.c	Sun Sep 23 22:16:02 2001 +0000
     1.3 @@ -449,7 +449,11 @@
     1.4  
     1.5  void Mac_InitOSKeymap(_THIS)
     1.6  {
     1.7 +	const void *KCHRPtr;
     1.8 +	UInt32 state;
     1.9 +	UInt32 value;
    1.10  	int i;
    1.11 +	int world = SDLK_WORLD_0;
    1.12  
    1.13  	/* Map the MAC keysyms */
    1.14  	for ( i=0; i<SDL_TABLESIZE(MAC_keymap); ++i )
    1.15 @@ -576,6 +580,64 @@
    1.16  	MAC_keymap[MK_IBOOK_UP] = SDLK_UP;
    1.17  	MAC_keymap[MK_IBOOK_LEFT] = SDLK_LEFT;
    1.18  #endif /* MacOS X */
    1.19 +
    1.20 +	/* Up there we setup a static scancode->keysym map. However, it will not
    1.21 +	 * work very well on international keyboard. Hence we now query MacOS
    1.22 +	 * for its own keymap to adjust our own mapping table. However, this is
    1.23 +	 * bascially only useful for ascii char keys. This is also the reason
    1.24 +	 * why we keep the static table, too.
    1.25 +	 */
    1.26 +	
    1.27 +	/* Get a pointer to the systems cached KCHR */
    1.28 +	KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
    1.29 +	if (KCHRPtr)
    1.30 +	{
    1.31 +		/* Loop over all 127 possible scan codes */
    1.32 +		for (i = 0; i < 0x7F; i++)
    1.33 +		{
    1.34 +			/* We pretend a clean start to begin with (i.e. no dead keys active */
    1.35 +			state = 0;
    1.36 +			
    1.37 +			/* Now translate the key code to a key value */
    1.38 +			value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
    1.39 +			
    1.40 +			/* If the state become 0, it was a dead key. We need to translate again,
    1.41 +			passing in the new state, to get the actual key value */
    1.42 +			if (state != 0)
    1.43 +				value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
    1.44 +			
    1.45 +			/* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
    1.46 +			if (value >= 128)	 /* Some non-ASCII char, map it to SDLK_WORLD_* */
    1.47 +				MAC_keymap[i] = world++;
    1.48 +			else if (value >= 32)	 /* non-control ASCII char */
    1.49 +				MAC_keymap[i] = value;
    1.50 +		}
    1.51 +	}
    1.52 +	
    1.53 +	/* The keypad codes are re-setup here, because the loop above cannot
    1.54 +	 * distinguish between a key on the keypad and a regular key. We maybe
    1.55 +	 * could get around this problem in another fashion: NSEvent's flags
    1.56 +	 * include a "NSNumericPadKeyMask" bit; we could check that and modify
    1.57 +	 * the symbol we return on the fly. However, this flag seems to exhibit
    1.58 +	 * some weird behaviour related to the num lock key
    1.59 +	 */
    1.60 +	MAC_keymap[MK_KP0] = SDLK_KP0;
    1.61 +	MAC_keymap[MK_KP1] = SDLK_KP1;
    1.62 +	MAC_keymap[MK_KP2] = SDLK_KP2;
    1.63 +	MAC_keymap[MK_KP3] = SDLK_KP3;
    1.64 +	MAC_keymap[MK_KP4] = SDLK_KP4;
    1.65 +	MAC_keymap[MK_KP5] = SDLK_KP5;
    1.66 +	MAC_keymap[MK_KP6] = SDLK_KP6;
    1.67 +	MAC_keymap[MK_KP7] = SDLK_KP7;
    1.68 +	MAC_keymap[MK_KP8] = SDLK_KP8;
    1.69 +	MAC_keymap[MK_KP9] = SDLK_KP9;
    1.70 +	MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS;
    1.71 +	MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS;
    1.72 +	MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD;
    1.73 +	MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS;
    1.74 +	MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE;
    1.75 +	MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
    1.76 +	MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER;
    1.77  }
    1.78  
    1.79  static SDL_keysym *TranslateKey(int scancode, int modifiers,