| | |
| | | /* |
| | | Simple DirectMedia Layer |
| | | Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> |
| | | Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> |
| | | |
| | | This software is provided 'as-is', without any express or implied |
| | | warranty. In no event will the authors be held liable for any damages |
| | |
| | | SDLK_KBDILLUMUP, |
| | | SDLK_EJECT, |
| | | SDLK_SLEEP, |
| | | SDLK_APP1, |
| | | SDLK_APP2, |
| | | SDLK_AUDIOREWIND, |
| | | SDLK_AUDIOFASTFORWARD, |
| | | }; |
| | | |
| | | static const char *SDL_scancode_names[SDL_NUM_SCANCODES] = { |
| | |
| | | "KBDIllumUp", |
| | | "Eject", |
| | | "Sleep", |
| | | "App1", |
| | | "App2", |
| | | "AudioRewind", |
| | | "AudioFastForward", |
| | | }; |
| | | |
| | | /* Taken from SDL_iconv() */ |
| | |
| | | #ifdef DEBUG_KEYBOARD |
| | | printf("Resetting keyboard\n"); |
| | | #endif |
| | | for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) { |
| | | for (scancode = (SDL_Scancode) 0; scancode < SDL_NUM_SCANCODES; ++scancode) { |
| | | if (keyboard->keystate[scancode] == SDL_PRESSED) { |
| | | SDL_SendKeyboardKey(SDL_RELEASED, scancode); |
| | | } |
| | |
| | | SDL_SetKeymap(int start, SDL_Keycode * keys, int length) |
| | | { |
| | | SDL_Keyboard *keyboard = &SDL_keyboard; |
| | | SDL_Scancode scancode; |
| | | |
| | | if (start < 0 || start + length > SDL_NUM_SCANCODES) { |
| | | return; |
| | | } |
| | | |
| | | SDL_memcpy(&keyboard->keymap[start], keys, sizeof(*keys) * length); |
| | | |
| | | /* The number key scancodes always map to the number key keycodes. |
| | | * On AZERTY layouts these technically are symbols, but users (and games) |
| | | * always think of them and view them in UI as number keys. |
| | | */ |
| | | keyboard->keymap[SDL_SCANCODE_0] = SDLK_0; |
| | | for (scancode = SDL_SCANCODE_1; scancode <= SDL_SCANCODE_9; ++scancode) { |
| | | keyboard->keymap[scancode] = SDLK_1 + (scancode - SDL_SCANCODE_1); |
| | | } |
| | | } |
| | | |
| | | void |
| | |
| | | int posted; |
| | | SDL_Keymod modifier; |
| | | SDL_Keycode keycode; |
| | | Uint16 modstate; |
| | | Uint32 type; |
| | | Uint8 repeat; |
| | | |
| | |
| | | break; |
| | | } |
| | | if (SDL_KEYDOWN == type) { |
| | | modstate = keyboard->modstate; |
| | | switch (keycode) { |
| | | case SDLK_NUMLOCKCLEAR: |
| | | keyboard->modstate ^= KMOD_NUM; |
| | |
| | | } |
| | | } else { |
| | | keyboard->modstate &= ~modifier; |
| | | modstate = keyboard->modstate; |
| | | } |
| | | |
| | | /* Post the event, if desired */ |
| | |
| | | event.key.repeat = repeat; |
| | | event.key.keysym.scancode = scancode; |
| | | event.key.keysym.sym = keycode; |
| | | event.key.keysym.mod = modstate; |
| | | event.key.keysym.mod = keyboard->modstate; |
| | | event.key.windowID = keyboard->focus ? keyboard->focus->id : 0; |
| | | posted = (SDL_PushEvent(&event) > 0); |
| | | } |
| | |
| | | { |
| | | SDL_Keyboard *keyboard = &SDL_keyboard; |
| | | |
| | | return keyboard->modstate; |
| | | return (SDL_Keymod) keyboard->modstate; |
| | | } |
| | | |
| | | void |
| | |
| | | { |
| | | SDL_Keyboard *keyboard = &SDL_keyboard; |
| | | |
| | | if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) { |
| | | if (((int)scancode) < ((int)SDL_SCANCODE_UNKNOWN) || scancode >= SDL_NUM_SCANCODES) { |
| | | SDL_InvalidParamError("scancode"); |
| | | return 0; |
| | | } |
| | |
| | | SDL_GetScancodeName(SDL_Scancode scancode) |
| | | { |
| | | const char *name; |
| | | if (scancode < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) { |
| | | if (((int)scancode) < ((int)SDL_SCANCODE_UNKNOWN) || scancode >= SDL_NUM_SCANCODES) { |
| | | SDL_InvalidParamError("scancode"); |
| | | return ""; |
| | | } |
| | |
| | | { |
| | | SDL_Keycode key; |
| | | |
| | | /* Check input */ |
| | | if (name == NULL) return SDLK_UNKNOWN; |
| | | /* Check input */ |
| | | if (name == NULL) { |
| | | return SDLK_UNKNOWN; |
| | | } |
| | | |
| | | /* If it's a single UTF-8 character, then that's the keycode itself */ |
| | | key = *(const unsigned char *)name; |