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

  event | Screen keyboard event

Definition at line 99 of file keyboard.c.

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

Referenced by pumpEvents().

{
int val;
SDL_Scancode scancode;
// Get the key value.
if (screen_get_event_property_iv(event, SCREEN_PROPERTY_SYM, &val) < 0) {
return;
}
// Skip unrecognized keys.
if ((val < 0) || (val >= SDL_TABLESIZE(key_to_sdl))) {
return;
}
// Translate to an SDL scan code.
scancode = key_to_sdl[val];
if (scancode == 0) {
return;
}
// Get event flags (key state).
if (screen_get_event_property_iv(event, SCREEN_PROPERTY_FLAGS, &val) < 0) {
return;
}
// Propagate the event to SDL.
// FIXME:
// Need to handle more key states (such as key combinations).
if (val & KEY_DOWN) {
SDL_SendKeyboardKey(SDL_PRESSED, scancode);
} else {
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
}
}
key_to_sdl
static int key_to_sdl[]
Definition: keyboard.c:33
SDL_SendKeyboardKey
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
Definition: SDL_keyboard.c:679
val
GLuint GLfloat * val
Definition: SDL_opengl_glext.h:1492
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_TABLESIZE
#define SDL_TABLESIZE(table)
Definition: SDL_stdinc.h:94
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49
SDL_Scancode
SDL_Scancode
The SDL keyboard scancode representation.
Definition: SDL_scancode.h:43

## 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().