Merge pull request #2703 from diablodiab/master

Enables keyboard to be mapped to gamepad buttons
This commit is contained in:
Twinaphex 2016-02-08 02:41:02 +01:00
commit 1924b8396b
3 changed files with 27 additions and 3 deletions

View File

@ -976,7 +976,11 @@ static void android_input_poll_input(void *data)
if (is_keyboard_id(id))
{
if (!predispatched) android_input_poll_event_type_keyboard(event, keycode, &handled);
if (!predispatched)
{
android_input_poll_event_type_keyboard(event, keycode, &handled);
android_input_poll_event_type_key(android_app, event, ANDROID_KEYBOARD_PORT, keycode, source, type_event, &handled);
}
}
else
android_input_poll_event_type_key(android_app,
@ -1110,7 +1114,8 @@ static int16_t android_input_state(void *data,
switch (device)
{
case RETRO_DEVICE_JOYPAD:
return input_joypad_pressed(android->joypad, port, binds[port], id);
return input_joypad_pressed(android->joypad, port, binds[port], id) ||
android_keyboard_port_input_pressed(binds[port],id);
case RETRO_DEVICE_ANALOG:
return input_joypad_analog(android->joypad, port, idx, id,
binds[port]);
@ -1156,6 +1161,9 @@ static bool android_input_key_pressed(void *data, int key)
android_input_t *android = (android_input_t*)data;
settings_t *settings = config_get_ptr();
if(android_keyboard_port_input_pressed(settings->input.binds[0],key))
return true;
if (input_joypad_pressed(android->joypad,
0, settings->input.binds[0], key))
return true;

View File

@ -21,7 +21,19 @@
#define MAX_KEYS ((LAST_KEYCODE + 7) / 8)
static uint8_t android_key_state[MAX_PADS][MAX_KEYS];
// First ports are used to keeping track of gamepad states. Last port is used for keyboard state
static uint8_t android_key_state[MAX_PADS+1][MAX_KEYS];
bool android_keyboard_port_input_pressed(const struct retro_keybind *binds, unsigned id)
{
if (id < RARCH_BIND_LIST_END)
{
const struct retro_keybind *bind = &binds[id];
unsigned bit = input_keymaps_translate_rk_to_keysym(binds[id].key);
return bind->valid && BIT_GET(android_key_state[ANDROID_KEYBOARD_PORT], bit);
}
return false;
}
bool android_keyboard_input_pressed(unsigned key)
{

View File

@ -135,6 +135,10 @@ enum {
#define MAX_PADS 8
#endif
#define ANDROID_KEYBOARD_PORT MAX_PADS
bool android_keyboard_port_input_pressed(const struct retro_keybind *binds, unsigned id);
bool android_keyboard_input_pressed(unsigned key);
uint8_t *android_keyboard_state_get(unsigned port);