src/events/SDL_keyboard.c
changeset 5218 572a73d71b5f
parent 5123 dc0dfdd58f27
child 5219 c1a92e61907d
equal deleted inserted replaced
5217:9c0593fa27d6 5218:572a73d71b5f
   560 
   560 
   561 void
   561 void
   562 SDL_ResetKeyboard(void)
   562 SDL_ResetKeyboard(void)
   563 {
   563 {
   564     SDL_Keyboard *keyboard = &SDL_keyboard;
   564     SDL_Keyboard *keyboard = &SDL_keyboard;
   565     SDL_ScanCode scancode;
   565     SDL_Scancode scancode;
   566 
   566 
   567     for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
   567     for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
   568         if (keyboard->keystate[scancode] == SDL_PRESSED) {
   568         if (keyboard->keystate[scancode] == SDL_PRESSED) {
   569             SDL_SendKeyboardKey(SDL_RELEASED, scancode);
   569             SDL_SendKeyboardKey(SDL_RELEASED, scancode);
   570         }
   570         }
   588 
   588 
   589     SDL_memcpy(&keyboard->keymap[start], keys, sizeof(*keys) * length);
   589     SDL_memcpy(&keyboard->keymap[start], keys, sizeof(*keys) * length);
   590 }
   590 }
   591 
   591 
   592 void
   592 void
   593 SDL_SetScancodeName(SDL_ScanCode scancode, const char *name)
   593 SDL_SetScancodeName(SDL_Scancode scancode, const char *name)
   594 {
   594 {
   595     SDL_scancode_names[scancode] = name;
   595     SDL_scancode_names[scancode] = name;
   596 }
   596 }
   597 
   597 
   598 SDL_Window *
   598 SDL_Window *
   636         }
   636         }
   637     }
   637     }
   638 }
   638 }
   639 
   639 
   640 int
   640 int
   641 SDL_SendKeyboardKey(Uint8 state, SDL_ScanCode scancode)
   641 SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
   642 {
   642 {
   643     SDL_Keyboard *keyboard = &SDL_keyboard;
   643     SDL_Keyboard *keyboard = &SDL_keyboard;
   644     int posted;
   644     int posted;
   645     Uint16 modstate;
   645     Uint16 modstate;
   646     Uint32 type;
   646     Uint32 type;
   847 
   847 
   848     keyboard->modstate = modstate;
   848     keyboard->modstate = modstate;
   849 }
   849 }
   850 
   850 
   851 SDLKey
   851 SDLKey
   852 SDL_GetKeyFromScancode(SDL_ScanCode scancode)
   852 SDL_GetKeyFromScancode(SDL_Scancode scancode)
   853 {
   853 {
   854     SDL_Keyboard *keyboard = &SDL_keyboard;
   854     SDL_Keyboard *keyboard = &SDL_keyboard;
   855 
   855 
   856     return keyboard->keymap[scancode];
   856     return keyboard->keymap[scancode];
   857 }
   857 }
   858 
   858 
   859 SDL_ScanCode
   859 SDL_Scancode
   860 SDL_GetScancodeFromKey(SDLKey key)
   860 SDL_GetScancodeFromKey(SDLKey key)
   861 {
   861 {
   862     SDL_Keyboard *keyboard = &SDL_keyboard;
   862     SDL_Keyboard *keyboard = &SDL_keyboard;
   863     SDL_ScanCode scancode;
   863     SDL_Scancode scancode;
   864 
   864 
   865     for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES;
   865     for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES;
   866          ++scancode) {
   866          ++scancode) {
   867         if (keyboard->keymap[scancode] == key) {
   867         if (keyboard->keymap[scancode] == key) {
   868             return scancode;
   868             return scancode;
   870     }
   870     }
   871     return SDL_SCANCODE_UNKNOWN;
   871     return SDL_SCANCODE_UNKNOWN;
   872 }
   872 }
   873 
   873 
   874 const char *
   874 const char *
   875 SDL_GetScancodeName(SDL_ScanCode scancode)
   875 SDL_GetScancodeName(SDL_Scancode scancode)
   876 {
   876 {
   877     const char *name = SDL_scancode_names[scancode];
   877     const char *name = SDL_scancode_names[scancode];
   878 
   878 
   879     if (name)
   879     if (name)
   880         return name;
   880         return name;
   888     static char name[8];
   888     static char name[8];
   889     char *end;
   889     char *end;
   890 
   890 
   891     if (key & SDLK_SCANCODE_MASK) {
   891     if (key & SDLK_SCANCODE_MASK) {
   892         return
   892         return
   893             SDL_GetScancodeName((SDL_ScanCode) (key & ~SDLK_SCANCODE_MASK));
   893             SDL_GetScancodeName((SDL_Scancode) (key & ~SDLK_SCANCODE_MASK));
   894     }
   894     }
   895 
   895 
   896     switch (key) {
   896     switch (key) {
   897     case SDLK_RETURN:
   897     case SDLK_RETURN:
   898         return SDL_GetScancodeName(SDL_SCANCODE_RETURN);
   898         return SDL_GetScancodeName(SDL_SCANCODE_RETURN);