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_SendKeyboardKeyAutoRelease (SDL_Scancode scancode)
 
void SDL_ReleaseAutoReleaseKeys (void)
 
SDL_bool SDL_HardwareKeyboardKeyPressed (void)
 
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

◆ SDL_GetDefaultKeymap()

void SDL_GetDefaultKeymap ( SDL_Keycode keymap)

Definition at line 592 of file SDL_keyboard.c.

593 {
595 }
#define SDL_memcpy
static const SDL_Keycode SDL_default_keymap[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:53

References SDL_default_keymap, and SDL_memcpy.

◆ SDL_HardwareKeyboardKeyPressed()

SDL_bool SDL_HardwareKeyboardKeyPressed ( void  )

Definition at line 834 of file SDL_keyboard.c.

835 {
836  SDL_Keyboard *keyboard = &SDL_keyboard;
837  SDL_Scancode scancode;
838 
839  for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) {
840  if ((keyboard->keysource[scancode] & KEYBOARD_HARDWARE) != 0) {
841  return SDL_TRUE;
842  }
843  }
844  return SDL_FALSE;
845 }
#define KEYBOARD_HARDWARE
Definition: SDL_keyboard.c:35
static SDL_Keyboard SDL_keyboard
Definition: SDL_keyboard.c:51
SDL_Scancode
The SDL keyboard scancode representation.
Definition: SDL_scancode.h:44
@ SDL_SCANCODE_UNKNOWN
Definition: SDL_scancode.h:45
@ SDL_NUM_SCANCODES
Definition: SDL_scancode.h:407
@ SDL_TRUE
Definition: SDL_stdinc.h:170
@ SDL_FALSE
Definition: SDL_stdinc.h:169
Uint8 keysource[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:45

References KEYBOARD_HARDWARE, SDL_Keyboard::keysource, SDL_FALSE, SDL_keyboard, SDL_NUM_SCANCODES, SDL_SCANCODE_UNKNOWN, and SDL_TRUE.

◆ SDL_KeyboardInit()

int SDL_KeyboardInit ( void  )

Definition at line 566 of file SDL_keyboard.c.

567 {
568  SDL_Keyboard *keyboard = &SDL_keyboard;
569 
570  /* Set the default keymap */
572  return (0);
573 }
SDL_Keycode keymap[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:47

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

Referenced by SDL_VideoInit().

◆ SDL_KeyboardQuit()

void SDL_KeyboardQuit ( void  )

Definition at line 891 of file SDL_keyboard.c.

892 {
893 }

Referenced by SDL_VideoQuit().

◆ SDL_ReleaseAutoReleaseKeys()

void SDL_ReleaseAutoReleaseKeys ( void  )

Definition at line 818 of file SDL_keyboard.c.

819 {
820  SDL_Keyboard *keyboard = &SDL_keyboard;
821  SDL_Scancode scancode;
822 
823  if (keyboard->autorelease_pending) {
824  for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES; ++scancode) {
825  if (keyboard->keysource[scancode] == KEYBOARD_AUTORELEASE) {
827  }
828  }
829  keyboard->autorelease_pending = SDL_FALSE;
830  }
831 }
#define SDL_RELEASED
Definition: SDL_events.h:49
static int SDL_SendKeyboardKeyInternal(Uint8 source, Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:683
#define KEYBOARD_AUTORELEASE
Definition: SDL_keyboard.c:36
SDL_bool autorelease_pending
Definition: SDL_keyboard.c:48

References SDL_Keyboard::autorelease_pending, KEYBOARD_AUTORELEASE, SDL_Keyboard::keysource, SDL_FALSE, SDL_keyboard, SDL_NUM_SCANCODES, SDL_RELEASED, SDL_SCANCODE_UNKNOWN, and SDL_SendKeyboardKeyInternal().

Referenced by SDL_PumpEvents().

◆ SDL_ResetKeyboard()

void SDL_ResetKeyboard ( void  )

Definition at line 576 of file SDL_keyboard.c.

577 {
578  SDL_Keyboard *keyboard = &SDL_keyboard;
579  SDL_Scancode scancode;
580 
581 #ifdef DEBUG_KEYBOARD
582  printf("Resetting keyboard\n");
583 #endif
584  for (scancode = (SDL_Scancode) 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
585  if (keyboard->keystate[scancode] == SDL_PRESSED) {
587  }
588  }
589 }
#define SDL_PRESSED
Definition: SDL_events.h:50
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:806
Uint8 keystate[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:46

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

Referenced by SDL_SetKeyboardFocus(), and SDL_ShowMessageBox().

◆ SDL_SendEditingText()

int SDL_SendEditingText ( const char *  text,
int  start,
int  end 
)

Definition at line 871 of file SDL_keyboard.c.

872 {
873  SDL_Keyboard *keyboard = &SDL_keyboard;
874  int posted;
875 
876  /* Post the event, if desired */
877  posted = 0;
880  event.edit.type = SDL_TEXTEDITING;
881  event.edit.windowID = keyboard->focus ? keyboard->focus->id : 0;
882  event.edit.start = start;
883  event.edit.length = length;
884  SDL_utf8strlcpy(event.edit.text, text, SDL_arraysize(event.edit.text));
885  posted = (SDL_PushEvent(&event) > 0);
886  }
887  return (posted);
888 }
#define SDL_PushEvent
#define SDL_utf8strlcpy
@ SDL_TEXTEDITING
Definition: SDL_events.h:100
#define SDL_GetEventState(type)
Definition: SDL_events.h:808
#define SDL_ENABLE
Definition: SDL_events.h:795
GLuint start
Definition: SDL_opengl.h:1571
struct _cl_event * event
GLuint GLsizei GLsizei * length
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:121
SDL_Window * focus
Definition: SDL_keyboard.c:43
Uint32 id
Definition: SDL_sysvideo.h:77
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47
General event structure.
Definition: SDL_events.h:592

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

Referenced by DBus_MessageFilter().

◆ SDL_SendKeyboardKey()

int SDL_SendKeyboardKey ( Uint8  state,
SDL_Scancode  scancode 
)

Definition at line 806 of file SDL_keyboard.c.

807 {
809 }
struct xkb_state * state

References KEYBOARD_HARDWARE, SDL_SendKeyboardKeyInternal(), and state.

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

◆ SDL_SendKeyboardKeyAutoRelease()

int SDL_SendKeyboardKeyAutoRelease ( SDL_Scancode  scancode)

Definition at line 812 of file SDL_keyboard.c.

813 {
815 }

References KEYBOARD_AUTORELEASE, SDL_PRESSED, and SDL_SendKeyboardKeyInternal().

◆ SDL_SendKeyboardText()

int SDL_SendKeyboardText ( const char *  text)

Definition at line 848 of file SDL_keyboard.c.

849 {
850  SDL_Keyboard *keyboard = &SDL_keyboard;
851  int posted;
852 
853  /* Don't post text events for unprintable characters */
854  if ((unsigned char)*text < ' ' || *text == 127) {
855  return 0;
856  }
857 
858  /* Post the event, if desired */
859  posted = 0;
862  event.text.type = SDL_TEXTINPUT;
863  event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
864  SDL_utf8strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
865  posted = (SDL_PushEvent(&event) > 0);
866  }
867  return (posted);
868 }
@ SDL_TEXTINPUT
Definition: SDL_events.h:101

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

Referenced by SDL_BApp::_HandleKey(), and DBus_MessageFilter().

◆ SDL_SetKeyboardFocus()

void SDL_SetKeyboardFocus ( SDL_Window window)

Definition at line 634 of file SDL_keyboard.c.

635 {
636  SDL_Keyboard *keyboard = &SDL_keyboard;
637 
638  if (keyboard->focus && !window) {
639  /* We won't get anymore keyboard messages, so reset keyboard state */
641  }
642 
643  /* See if the current window has lost focus */
644  if (keyboard->focus && keyboard->focus != window) {
645 
646  /* new window shouldn't think it has mouse captured. */
648 
649  /* old window must lose an existing mouse capture. */
650  if (keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE) {
651  SDL_CaptureMouse(SDL_FALSE); /* drop the capture. */
653  }
654 
656  0, 0);
657 
658  /* Ensures IME compositions are committed */
661  if (video && video->StopTextInput) {
662  video->StopTextInput(video);
663  }
664  }
665  }
666 
667  keyboard->focus = window;
668 
669  if (keyboard->focus) {
671  0, 0);
672 
675  if (video && video->StartTextInput) {
676  video->StartTextInput(video);
677  }
678  }
679  }
680 }
#define SDL_assert(condition)
Definition: SDL_assert.h:171
#define SDL_CaptureMouse
#define SDL_EventState
#define SDL_QUERY
Definition: SDL_events.h:792
void SDL_ResetKeyboard(void)
Definition: SDL_keyboard.c:576
SDL_VideoDevice * SDL_GetVideoDevice(void)
Definition: SDL_video.c:587
@ SDL_WINDOW_MOUSE_CAPTURE
Definition: SDL_video.h:115
@ SDL_WINDOWEVENT_FOCUS_LOST
Definition: SDL_video.h:166
@ SDL_WINDOWEVENT_FOCUS_GAINED
Definition: SDL_video.h:165
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
void(* StartTextInput)(_THIS)
Definition: SDL_sysvideo.h:297
void(* StopTextInput)(_THIS)
Definition: SDL_sysvideo.h:298
Uint32 flags
Definition: SDL_sysvideo.h:84

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_SetKeymap()

void SDL_SetKeymap ( int  start,
SDL_Keycode keys,
int  length 
)

Definition at line 598 of file SDL_keyboard.c.

599 {
600  SDL_Keyboard *keyboard = &SDL_keyboard;
601  SDL_Scancode scancode;
602 
604  return;
605  }
606 
607  SDL_memcpy(&keyboard->keymap[start], keys, sizeof(*keys) * length);
608 
609  /* The number key scancodes always map to the number key keycodes.
610  * On AZERTY layouts these technically are symbols, but users (and games)
611  * always think of them and view them in UI as number keys.
612  */
613  keyboard->keymap[SDL_SCANCODE_0] = SDLK_0;
614  for (scancode = SDL_SCANCODE_1; scancode <= SDL_SCANCODE_9; ++scancode) {
615  keyboard->keymap[scancode] = SDLK_1 + (scancode - SDL_SCANCODE_1);
616  }
617 }
@ SDLK_0
Definition: SDL_keycode.h:74
@ SDLK_1
Definition: SDL_keycode.h:75
@ SDL_SCANCODE_9
Definition: SDL_scancode.h:89
@ SDL_SCANCODE_0
Definition: SDL_scancode.h:90
@ SDL_SCANCODE_1
Definition: SDL_scancode.h:81

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_SetScancodeName()

void SDL_SetScancodeName ( SDL_Scancode  scancode,
const char *  name 
)

Definition at line 620 of file SDL_keyboard.c.

621 {
622  SDL_scancode_names[scancode] = name;
623 }
static const char * SDL_scancode_names[SDL_NUM_SCANCODES]
Definition: SDL_keyboard.c:286
GLuint const GLchar * name

References SDL_scancode_names.

◆ SDL_ToggleModState()

void SDL_ToggleModState ( const SDL_Keymod  modstate,
const SDL_bool  toggle 
)

Definition at line 924 of file SDL_keyboard.c.

925 {
926  SDL_Keyboard *keyboard = &SDL_keyboard;
927  if (toggle) {
928  keyboard->modstate |= modstate;
929  } else {
930  keyboard->modstate &= ~modstate;
931  }
932 }
Uint16 modstate
Definition: SDL_keyboard.c:44

References SDL_Keyboard::modstate, and SDL_keyboard.

◆ SDL_UCS4ToUTF8()

char* SDL_UCS4ToUTF8 ( Uint32  ch,
char *  dst 
)

Definition at line 524 of file SDL_keyboard.c.

525 {
526  Uint8 *p = (Uint8 *) dst;
527  if (ch <= 0x7F) {
528  *p = (Uint8) ch;
529  ++dst;
530  } else if (ch <= 0x7FF) {
531  p[0] = 0xC0 | (Uint8) ((ch >> 6) & 0x1F);
532  p[1] = 0x80 | (Uint8) (ch & 0x3F);
533  dst += 2;
534  } else if (ch <= 0xFFFF) {
535  p[0] = 0xE0 | (Uint8) ((ch >> 12) & 0x0F);
536  p[1] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
537  p[2] = 0x80 | (Uint8) (ch & 0x3F);
538  dst += 3;
539  } else if (ch <= 0x1FFFFF) {
540  p[0] = 0xF0 | (Uint8) ((ch >> 18) & 0x07);
541  p[1] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
542  p[2] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
543  p[3] = 0x80 | (Uint8) (ch & 0x3F);
544  dst += 4;
545  } else if (ch <= 0x3FFFFFF) {
546  p[0] = 0xF8 | (Uint8) ((ch >> 24) & 0x03);
547  p[1] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
548  p[2] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
549  p[3] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
550  p[4] = 0x80 | (Uint8) (ch & 0x3F);
551  dst += 5;
552  } else {
553  p[0] = 0xFC | (Uint8) ((ch >> 30) & 0x01);
554  p[1] = 0x80 | (Uint8) ((ch >> 24) & 0x3F);
555  p[2] = 0x80 | (Uint8) ((ch >> 18) & 0x3F);
556  p[3] = 0x80 | (Uint8) ((ch >> 12) & 0x3F);
557  p[4] = 0x80 | (Uint8) ((ch >> 6) & 0x3F);
558  p[5] = 0x80 | (Uint8) (ch & 0x3F);
559  dst += 6;
560  }
561  return dst;
562 }
GLenum GLenum dst
GLfloat GLfloat p
uint8_t Uint8
Definition: SDL_stdinc.h:185

Referenced by SDL_GetKeyName().