(Key Events) Add modifier flag argument; plus cleanup.

This commit is contained in:
meancoot 2012-12-07 03:18:18 -05:00
parent e60bb1d168
commit be1fdd419b
2 changed files with 42 additions and 16 deletions

View File

@ -257,19 +257,29 @@ static void gfx_ctx_check_window(bool *quit,
case SDL_KEYDOWN:
case SDL_KEYUP:
if(g_extern.system.key_event)
if (g_extern.system.key_event)
{
static bool unicodeOn = false;
SDL_EnableUNICODE(true);
if(!unicodeOn)
uint16_t mods = 0;
if (event.key.keysym.mod)
{
unicodeOn = true;
SDL_EnableUNICODE(true);
mods |= (event.key.keysym.mod & KMOD_CTRL) ? RETROKMOD_CTRL : 0;
mods |= (event.key.keysym.mod & KMOD_ALT) ? RETROKMOD_ALT : 0;
mods |= (event.key.keysym.mod & KMOD_SHIFT) ? RETROKMOD_SHIFT : 0;
mods |= (event.key.keysym.mod & KMOD_META) ? RETROKMOD_META : 0;
mods |= (event.key.keysym.mod & KMOD_NUM) ? RETROKMOD_NUMLOCK : 0;
mods |= (event.key.keysym.mod & KMOD_CAPS) ? RETROKMOD_CAPSLOCK : 0;
// TODO: What is KMOD_MODE in SDL?
mods |= (event.key.keysym.mod & KMOD_MODE) ? RETROKMOD_SCROLLOCK : 0;
}
// For now it seems that all RETROK_* constant values match the SDLK_* values.
// Ultimately the table in sdl_input.c should be used in case this changes.
g_extern.system.key_event(event.type == SDL_KEYDOWN, event.key.keysym.sym, event.key.keysym.unicode);
// TODO: event.key.keysym.unicode is UTF-16
g_extern.system.key_event(event.type == SDL_KEYDOWN, event.key.keysym.sym, event.key.keysym.unicode, mods);
}
break;
}

View File

@ -310,6 +310,21 @@ enum retro_key
RETROK_LAST
};
enum retro_mod
{
RETROKMOD_NONE = 0x0000,
RETROKMOD_SHIFT = 0x01,
RETROKMOD_CTRL = 0x02,
RETROKMOD_ALT = 0x04,
RETROKMOD_META = 0x08,
RETROKMOD_NUMLOCK = 0x10,
RETROKMOD_CAPSLOCK = 0x20,
RETROKMOD_SCROLLOCK = 0x40
};
// Environment commands.
#define RETRO_ENVIRONMENT_SET_ROTATION 1 // const unsigned * --
// Sets screen rotation of graphics.
@ -396,8 +411,9 @@ enum retro_key
// Callback type passed in RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. Called by the frontend in response to keyboard events.
// down is set if the key is being pressed, or false if it is being released.
// keycode is the RETROK value of the char.
// character is the text character of the pressed key. (UTF?)
typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode, unsigned character);
// character is the text character of the pressed key. (UTF-32).
// key_modifiers is a set of RETROKMOD values or'ed together.
typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode, uint32_t character, uint16_t key_modifiers);
struct retro_keyboard_callback
{