SDL  2.0
SDL_keyboard_c.h File Reference
#include "../SDL_internal.h"
#include "SDL_keycode.h"
#include "SDL_events.h"
+ Include dependency graph for SDL_keyboard_c.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int SDL_KeyboardInit (void)
void SDL_ResetKeyboard (void)
void SDL_GetDefaultKeymap (SDL_Keycode *keymap)
void SDL_SetKeymap (int start, SDL_Keycode *keys, int length)
void SDL_SetScancodeName (SDL_Scancode scancode, const char *name)
void SDL_SetKeyboardFocus (SDL_Window *window)
int SDL_SendKeyboardKey (Uint8 state, SDL_Scancode scancode)
int SDL_SendKeyboardText (const char *text)
int SDL_SendEditingText (const char *text, int start, int end)
void SDL_KeyboardQuit (void)
char * SDL_UCS4ToUTF8 (Uint32 ch, char *dst)
void SDL_ToggleModState (const SDL_Keymod modstate, const SDL_bool toggle)

Function Documentation

void SDL_GetDefaultKeymap ( SDL_Keycode keymap)

Definition at line 588 of file SDL_keyboard.c.

References SDL_default_keymap, and SDL_memcpy.

int SDL_KeyboardInit ( void  )

Definition at line 562 of file SDL_keyboard.c.

References SDL_Keyboard::keymap, SDL_default_keymap, SDL_keyboard, and SDL_memcpy.

Referenced by SDL_VideoInit().

{
SDL_Keyboard *keyboard = &SDL_keyboard;
/* Set the default keymap */
return (0);
}
void SDL_KeyboardQuit ( void  )

Definition at line 832 of file SDL_keyboard.c.

Referenced by SDL_VideoQuit().

{
}
void SDL_ResetKeyboard ( void  )

Definition at line 572 of file SDL_keyboard.c.

References SDL_Keyboard::keystate, SDL_keyboard, SDL_NUM_SCANCODES, SDL_PRESSED, SDL_RELEASED, and SDL_SendKeyboardKey().

Referenced by SDL_SetKeyboardFocus(), and SDL_ShowMessageBox().

{
SDL_Keyboard *keyboard = &SDL_keyboard;
SDL_Scancode scancode;
#ifdef DEBUG_KEYBOARD
printf("Resetting keyboard\n");
#endif
for (scancode = (SDL_Scancode) 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
if (keyboard->keystate[scancode] == SDL_PRESSED) {
}
}
}
int SDL_SendEditingText ( const char *  text,
int  start,
int  end 
)

Definition at line 812 of file SDL_keyboard.c.

References SDL_Event::edit, SDL_Keyboard::focus, SDL_Window::id, SDL_arraysize, SDL_ENABLE, SDL_GetEventState, SDL_keyboard, SDL_PushEvent, SDL_TEXTEDITING, SDL_utf8strlcpy, and SDL_TextEditingEvent::text.

{
SDL_Keyboard *keyboard = &SDL_keyboard;
int posted;
/* Post the event, if desired */
posted = 0;
event.edit.type = SDL_TEXTEDITING;
event.edit.windowID = keyboard->focus ? keyboard->focus->id : 0;
event.edit.start = start;
event.edit.length = length;
posted = (SDL_PushEvent(&event) > 0);
}
return (posted);
}
int SDL_SendKeyboardKey ( Uint8  state,
SDL_Scancode  scancode 
)

Definition at line 679 of file SDL_keyboard.c.

References SDL_Keyboard::focus, SDL_Window::id, SDL_Keyboard::keymap, SDL_Keyboard::keystate, KMOD_CAPS, KMOD_LALT, KMOD_LCTRL, KMOD_LGUI, KMOD_LSHIFT, KMOD_MODE, KMOD_NONE, KMOD_NUM, KMOD_RALT, KMOD_RCTRL, KMOD_RGUI, KMOD_RSHIFT, SDL_Keyboard::modstate, SDL_ENABLE, SDL_GetEventState, SDL_GetScancodeName, SDL_keyboard, SDL_KEYDOWN, SDL_KEYUP, SDL_PRESSED, SDL_PushEvent, SDL_RELEASED, SDLK_CAPSLOCK, SDLK_LALT, SDLK_LCTRL, SDLK_LGUI, SDLK_LSHIFT, SDLK_MODE, SDLK_NUMLOCKCLEAR, SDLK_RALT, SDLK_RCTRL, SDLK_RGUI, SDLK_RSHIFT, and state.

Referenced by SDL_BApp::_HandleKey(), handleKeyboardEvent(), SDL_ResetKeyboard(), and WINRT_OnBackButtonPressed().

{
SDL_Keyboard *keyboard = &SDL_keyboard;
int posted;
SDL_Keymod modifier;
SDL_Keycode keycode;
Uint8 repeat;
if (!scancode) {
return 0;
}
#ifdef DEBUG_KEYBOARD
printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode),
state == SDL_PRESSED ? "pressed" : "released");
#endif
/* Figure out what type of event this is */
switch (state) {
type = SDL_KEYDOWN;
break;
type = SDL_KEYUP;
break;
default:
/* Invalid state -- bail */
return 0;
}
/* Drop events that don't change state */
repeat = (state && keyboard->keystate[scancode]);
if (keyboard->keystate[scancode] == state && !repeat) {
#if 0
printf("Keyboard event didn't change state - dropped!\n");
#endif
return 0;
}
/* Update internal keyboard state */
keyboard->keystate[scancode] = state;
keycode = keyboard->keymap[scancode];
/* Update modifiers state if applicable */
switch (keycode) {
case SDLK_LCTRL:
modifier = KMOD_LCTRL;
break;
case SDLK_RCTRL:
modifier = KMOD_RCTRL;
break;
modifier = KMOD_LSHIFT;
break;
modifier = KMOD_RSHIFT;
break;
case SDLK_LALT:
modifier = KMOD_LALT;
break;
case SDLK_RALT:
modifier = KMOD_RALT;
break;
case SDLK_LGUI:
modifier = KMOD_LGUI;
break;
case SDLK_RGUI:
modifier = KMOD_RGUI;
break;
case SDLK_MODE:
modifier = KMOD_MODE;
break;
default:
modifier = KMOD_NONE;
break;
}
if (SDL_KEYDOWN == type) {
switch (keycode) {
keyboard->modstate ^= KMOD_NUM;
break;
keyboard->modstate ^= KMOD_CAPS;
break;
default:
keyboard->modstate |= modifier;
break;
}
} else {
keyboard->modstate &= ~modifier;
}
/* Post the event, if desired */
posted = 0;
if (SDL_GetEventState(type) == SDL_ENABLE) {
event.key.type = type;
event.key.state = state;
event.key.repeat = repeat;
event.key.keysym.scancode = scancode;
event.key.keysym.sym = keycode;
event.key.keysym.mod = keyboard->modstate;
event.key.windowID = keyboard->focus ? keyboard->focus->id : 0;
posted = (SDL_PushEvent(&event) > 0);
}
return (posted);
}
int SDL_SendKeyboardText ( const char *  text)

Definition at line 789 of file SDL_keyboard.c.

References SDL_Keyboard::focus, SDL_Window::id, SDL_arraysize, SDL_ENABLE, SDL_GetEventState, SDL_keyboard, SDL_PushEvent, SDL_TEXTINPUT, SDL_utf8strlcpy, SDL_TextInputEvent::text, and SDL_Event::text.

Referenced by SDL_BApp::_HandleKey().

{
SDL_Keyboard *keyboard = &SDL_keyboard;
int posted;
/* Don't post text events for unprintable characters */
if ((unsigned char)*text < ' ' || *text == 127) {
return 0;
}
/* Post the event, if desired */
posted = 0;
event.text.type = SDL_TEXTINPUT;
event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
posted = (SDL_PushEvent(&event) > 0);
}
return (posted);
}
void SDL_SetKeyboardFocus ( SDL_Window window)

Definition at line 630 of file SDL_keyboard.c.

References SDL_Window::flags, SDL_Keyboard::focus, SDL_assert, SDL_CaptureMouse, SDL_EventState, SDL_FALSE, SDL_GetVideoDevice(), SDL_keyboard, SDL_QUERY, SDL_ResetKeyboard(), SDL_SendWindowEvent(), SDL_TEXTINPUT, SDL_WINDOW_MOUSE_CAPTURE, SDL_WINDOWEVENT_FOCUS_GAINED, SDL_WINDOWEVENT_FOCUS_LOST, SDL_VideoDevice::StartTextInput, and SDL_VideoDevice::StopTextInput.

Referenced by SDL_BApp::_HandleKeyboardFocus(), and SDL_DestroyWindow().

{
SDL_Keyboard *keyboard = &SDL_keyboard;
if (keyboard->focus && !window) {
/* We won't get anymore keyboard messages, so reset keyboard state */
}
/* See if the current window has lost focus */
if (keyboard->focus && keyboard->focus != window) {
/* new window shouldn't think it has mouse captured. */
SDL_assert(!window || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE));
/* old window must lose an existing mouse capture. */
if (keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE) {
SDL_CaptureMouse(SDL_FALSE); /* drop the capture. */
}
0, 0);
/* Ensures IME compositions are committed */
if (video && video->StopTextInput) {
video->StopTextInput(video);
}
}
}
keyboard->focus = window;
if (keyboard->focus) {
0, 0);
if (video && video->StartTextInput) {
video->StartTextInput(video);
}
}
}
}
void SDL_SetKeymap ( int  start,
SDL_Keycode keys,
int  length 
)

Definition at line 594 of file SDL_keyboard.c.

References SDL_Keyboard::keymap, SDL_keyboard, SDL_memcpy, SDL_NUM_SCANCODES, SDL_SCANCODE_0, SDL_SCANCODE_1, SDL_SCANCODE_9, SDLK_0, and SDLK_1.

{
SDL_Keyboard *keyboard = &SDL_keyboard;
SDL_Scancode scancode;
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.
*/
for (scancode = SDL_SCANCODE_1; scancode <= SDL_SCANCODE_9; ++scancode) {
keyboard->keymap[scancode] = SDLK_1 + (scancode - SDL_SCANCODE_1);
}
}
void SDL_SetScancodeName ( SDL_Scancode  scancode,
const char *  name 
)

Definition at line 616 of file SDL_keyboard.c.

References SDL_scancode_names.

{
SDL_scancode_names[scancode] = name;
}
void SDL_ToggleModState ( const SDL_Keymod  modstate,
const SDL_bool  toggle 
)

Definition at line 865 of file SDL_keyboard.c.

References SDL_Keyboard::modstate, and SDL_keyboard.

{
SDL_Keyboard *keyboard = &SDL_keyboard;
if (toggle) {
keyboard->modstate |= modstate;
} else {
keyboard->modstate &= ~modstate;
}
}
char* SDL_UCS4ToUTF8 ( Uint32  ch,
char *  dst 
)

Definition at line 520 of file SDL_keyboard.c.

Referenced by SDL_GetKeyName().

{
Uint8 *p = (Uint8 *) dst;
if (ch <= 0x7F) {
*p = (Uint8) ch;
++dst;
} else if (ch <= 0x7FF) {
p[0] = 0xC0 | (Uint8) ((ch >> 6) & 0x1F);
p[1] = 0x80 | (Uint8) (ch & 0x3F);
dst += 2;
} else if (ch <= 0xFFFF) {
p[0] = 0xE0 | (Uint8) ((ch >> 12) & 0x0F);
p[1] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
p[2] = 0x80 | (Uint8) (ch & 0x3F);
dst += 3;
} else if (ch <= 0x1FFFFF) {
p[0] = 0xF0 | (Uint8) ((ch >> 18) & 0x07);
p[1] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
p[2] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
p[3] = 0x80 | (Uint8) (ch & 0x3F);
dst += 4;
} else if (ch <= 0x3FFFFFF) {
p[0] = 0xF8 | (Uint8) ((ch >> 24) & 0x03);
p[1] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
p[2] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
p[3] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
p[4] = 0x80 | (Uint8) (ch & 0x3F);
dst += 5;
} else {
p[0] = 0xFC | (Uint8) ((ch >> 30) & 0x01);
p[1] = 0x80 | (Uint8) ((ch >> 24) & 0x3F);
p[2] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
p[3] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
p[4] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
p[5] = 0x80 | (Uint8) (ch & 0x3F);
dst += 6;
}
return dst;
}