comparison src/video/maccommon/SDL_macevents.c @ 198:49bf25403f5e

*** empty log message ***
author Sam Lantinga <slouken@libsdl.org>
date Sun, 23 Sep 2001 22:16:02 +0000
parents e92aa316c517
children e8157fcb3114
comparison
equal deleted inserted replaced
197:ef78524e5f59 198:49bf25403f5e
447 } 447 }
448 } 448 }
449 449
450 void Mac_InitOSKeymap(_THIS) 450 void Mac_InitOSKeymap(_THIS)
451 { 451 {
452 const void *KCHRPtr;
453 UInt32 state;
454 UInt32 value;
452 int i; 455 int i;
456 int world = SDLK_WORLD_0;
453 457
454 /* Map the MAC keysyms */ 458 /* Map the MAC keysyms */
455 for ( i=0; i<SDL_TABLESIZE(MAC_keymap); ++i ) 459 for ( i=0; i<SDL_TABLESIZE(MAC_keymap); ++i )
456 MAC_keymap[i] = SDLK_UNKNOWN; 460 MAC_keymap[i] = SDLK_UNKNOWN;
457 461
574 MAC_keymap[MK_IBOOK_RIGHT] = SDLK_RIGHT; 578 MAC_keymap[MK_IBOOK_RIGHT] = SDLK_RIGHT;
575 MAC_keymap[MK_IBOOK_DOWN] = SDLK_DOWN; 579 MAC_keymap[MK_IBOOK_DOWN] = SDLK_DOWN;
576 MAC_keymap[MK_IBOOK_UP] = SDLK_UP; 580 MAC_keymap[MK_IBOOK_UP] = SDLK_UP;
577 MAC_keymap[MK_IBOOK_LEFT] = SDLK_LEFT; 581 MAC_keymap[MK_IBOOK_LEFT] = SDLK_LEFT;
578 #endif /* MacOS X */ 582 #endif /* MacOS X */
583
584 /* Up there we setup a static scancode->keysym map. However, it will not
585 * work very well on international keyboard. Hence we now query MacOS
586 * for its own keymap to adjust our own mapping table. However, this is
587 * bascially only useful for ascii char keys. This is also the reason
588 * why we keep the static table, too.
589 */
590
591 /* Get a pointer to the systems cached KCHR */
592 KCHRPtr = (void *)GetScriptManagerVariable(smKCHRCache);
593 if (KCHRPtr)
594 {
595 /* Loop over all 127 possible scan codes */
596 for (i = 0; i < 0x7F; i++)
597 {
598 /* We pretend a clean start to begin with (i.e. no dead keys active */
599 state = 0;
600
601 /* Now translate the key code to a key value */
602 value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
603
604 /* If the state become 0, it was a dead key. We need to translate again,
605 passing in the new state, to get the actual key value */
606 if (state != 0)
607 value = KeyTranslate(KCHRPtr, i, &state) & 0xff;
608
609 /* Now we should have an ascii value, or 0. Try to figure out to which SDL symbol it maps */
610 if (value >= 128) /* Some non-ASCII char, map it to SDLK_WORLD_* */
611 MAC_keymap[i] = world++;
612 else if (value >= 32) /* non-control ASCII char */
613 MAC_keymap[i] = value;
614 }
615 }
616
617 /* The keypad codes are re-setup here, because the loop above cannot
618 * distinguish between a key on the keypad and a regular key. We maybe
619 * could get around this problem in another fashion: NSEvent's flags
620 * include a "NSNumericPadKeyMask" bit; we could check that and modify
621 * the symbol we return on the fly. However, this flag seems to exhibit
622 * some weird behaviour related to the num lock key
623 */
624 MAC_keymap[MK_KP0] = SDLK_KP0;
625 MAC_keymap[MK_KP1] = SDLK_KP1;
626 MAC_keymap[MK_KP2] = SDLK_KP2;
627 MAC_keymap[MK_KP3] = SDLK_KP3;
628 MAC_keymap[MK_KP4] = SDLK_KP4;
629 MAC_keymap[MK_KP5] = SDLK_KP5;
630 MAC_keymap[MK_KP6] = SDLK_KP6;
631 MAC_keymap[MK_KP7] = SDLK_KP7;
632 MAC_keymap[MK_KP8] = SDLK_KP8;
633 MAC_keymap[MK_KP9] = SDLK_KP9;
634 MAC_keymap[MK_KP_MINUS] = SDLK_KP_MINUS;
635 MAC_keymap[MK_KP_PLUS] = SDLK_KP_PLUS;
636 MAC_keymap[MK_KP_PERIOD] = SDLK_KP_PERIOD;
637 MAC_keymap[MK_KP_EQUALS] = SDLK_KP_EQUALS;
638 MAC_keymap[MK_KP_DIVIDE] = SDLK_KP_DIVIDE;
639 MAC_keymap[MK_KP_MULTIPLY] = SDLK_KP_MULTIPLY;
640 MAC_keymap[MK_KP_ENTER] = SDLK_KP_ENTER;
579 } 641 }
580 642
581 static SDL_keysym *TranslateKey(int scancode, int modifiers, 643 static SDL_keysym *TranslateKey(int scancode, int modifiers,
582 SDL_keysym *keysym, int pressed) 644 SDL_keysym *keysym, int pressed)
583 { 645 {