SDL  2.0
keyboard.c File Reference
#include "../../SDL_internal.h"
#include "../../events/SDL_keyboard_c.h"
#include "SDL_scancode.h"
#include "SDL_events.h"
#include "sdl_qnx.h"
#include <sys/keycodes.h>
+ Include dependency graph for keyboard.c:

Go to the source code of this file.

Functions

void handleKeyboardEvent (screen_event_t event)
 

Variables

static int key_to_sdl []
 

Function Documentation

◆ handleKeyboardEvent()

void handleKeyboardEvent ( screen_event_t  event)

Called from the event dispatcher when a keyboard event is encountered. Translates the event such that it can be handled by SDL.

Parameters
eventScreen keyboard event

Definition at line 99 of file keyboard.c.

100 {
101  int val;
102  SDL_Scancode scancode;
103 
104  // Get the key value.
105  if (screen_get_event_property_iv(event, SCREEN_PROPERTY_SYM, &val) < 0) {
106  return;
107  }
108 
109  // Skip unrecognized keys.
110  if ((val < 0) || (val >= SDL_TABLESIZE(key_to_sdl))) {
111  return;
112  }
113 
114  // Translate to an SDL scan code.
115  scancode = key_to_sdl[val];
116  if (scancode == 0) {
117  return;
118  }
119 
120  // Get event flags (key state).
121  if (screen_get_event_property_iv(event, SCREEN_PROPERTY_FLAGS, &val) < 0) {
122  return;
123  }
124 
125  // Propagate the event to SDL.
126  // FIXME:
127  // Need to handle more key states (such as key combinations).
128  if (val & KEY_DOWN) {
129  SDL_SendKeyboardKey(SDL_PRESSED, scancode);
130  } else {
132  }
133 }

References key_to_sdl, SDL_PRESSED, SDL_RELEASED, SDL_SendKeyboardKey(), and SDL_TABLESIZE.

Referenced by pumpEvents().

Variable Documentation

◆ key_to_sdl

int key_to_sdl[]
static

A map thta translates Screen key names to SDL scan codes. This map is incomplete, but should include most major keys.

Definition at line 33 of file keyboard.c.

Referenced by handleKeyboardEvent().

SDL_Scancode
SDL_Scancode
The SDL keyboard scancode representation.
Definition: SDL_scancode.h:43
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49
SDL_SendKeyboardKey
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:679
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2652
key_to_sdl
static int key_to_sdl[]
Definition: keyboard.c:33
SDL_TABLESIZE
#define SDL_TABLESIZE(table)
Definition: SDL_stdinc.h:116
val
GLuint GLfloat * val
Definition: SDL_opengl_glext.h:1495