Some fixes for gamepad buttons

This commit is contained in:
Deve 2018-02-08 22:34:53 +01:00
parent 7210992e3d
commit a18351c052

View File

@ -575,6 +575,7 @@ s32 CIrrDeviceAndroid::handleKeyboard(AInputEvent* androidEvent)
int32_t keyAction = AKeyEvent_getAction(androidEvent);
int32_t keyMetaState = AKeyEvent_getMetaState(androidEvent);
int32_t keyRepeat = AKeyEvent_getRepeatCount(androidEvent);
int32_t scanCode = AKeyEvent_getScanCode(androidEvent);
if (keyAction == AKEY_EVENT_ACTION_DOWN)
{
@ -610,21 +611,27 @@ s32 CIrrDeviceAndroid::handleKeyboard(AInputEvent* androidEvent)
getKeyChar(event);
}
// If button doesn't return key code, then at least use device-specific
// scan code, because it's better than nothing
if (event.KeyInput.Key == 0)
{
event.KeyInput.Key = (EKEY_CODE)scanCode;
}
// Handle an event when back button in pressed just like an escape key
// and also avoid repeating the event to avoid some strange behaviour
if (event.KeyInput.SystemKeyCode == AKEYCODE_BACK)
{
status = 1;
if (event.KeyInput.PressedDown == false || keyRepeat > 0)
if (event.KeyInput.SystemKeyCode == AKEYCODE_BACK &&
(event.KeyInput.PressedDown == false || keyRepeat > 0))
{
ignore_event = true;
}
}
// Mark escape key event as handled by application to avoid receiving
// AKEYCODE_BACK key event
if (event.KeyInput.SystemKeyCode == AKEYCODE_ESCAPE)
// Mark escape key and gamepad buttons as handled by application to avoid
// receiving duplicated events
if (event.KeyInput.SystemKeyCode == AKEYCODE_ESCAPE ||
event.KeyInput.SystemKeyCode == AKEYCODE_BACK ||
(event.KeyInput.SystemKeyCode >= AKEYCODE_BUTTON_A &&
event.KeyInput.SystemKeyCode <= AKEYCODE_BUTTON_MODE))
{
status = 1;
}
@ -740,6 +747,11 @@ s32 CIrrDeviceAndroid::handleGamepad(AInputEvent* androidEvent)
int32_t keyCode = AKeyEvent_getKeyCode(androidEvent);
int32_t keyAction = AKeyEvent_getAction(androidEvent);
int32_t keyRepeat = AKeyEvent_getRepeatCount(androidEvent);
int32_t scanCode = AKeyEvent_getScanCode(androidEvent);
if (keyRepeat == 0)
{
bool ignore_event = false;
SEvent event;
event.EventType = EET_KEY_INPUT_EVENT;
@ -750,15 +762,15 @@ s32 CIrrDeviceAndroid::handleGamepad(AInputEvent* androidEvent)
event.KeyInput.SystemKeyCode = (u32)keyCode;
event.KeyInput.Key = KeyMap[keyCode];
// Handle an event when back button in pressed just like an escape key
// and also avoid repeating the event to avoid some strange behaviour
if (event.KeyInput.SystemKeyCode == AKEYCODE_BACK)
if (event.KeyInput.Key == 0)
{
status = 1;
ignore = (event.KeyInput.PressedDown == false || keyRepeat > 0);
event.KeyInput.Key = (EKEY_CODE)scanCode;
}
postEventFromUser(event);
}
status = 1;
break;
}
default:
@ -874,7 +886,7 @@ void CIrrDeviceAndroid::createKeyMap()
// following look like controller inputs
KeyMap[AKEYCODE_BUTTON_A] = IRR_KEY_RETURN;
KeyMap[AKEYCODE_BUTTON_B] = IRR_KEY_BACK;
KeyMap[AKEYCODE_BUTTON_B] = IRR_KEY_ESCAPE;
KeyMap[AKEYCODE_BUTTON_C] = IRR_KEY_2;
KeyMap[AKEYCODE_BUTTON_X] = IRR_KEY_3;
KeyMap[AKEYCODE_BUTTON_Y] = IRR_KEY_4;
@ -886,7 +898,7 @@ void CIrrDeviceAndroid::createKeyMap()
KeyMap[AKEYCODE_BUTTON_THUMBL] = IRR_KEY_RETURN;
KeyMap[AKEYCODE_BUTTON_THUMBR] = IRR_KEY_RETURN;
KeyMap[AKEYCODE_BUTTON_START] = IRR_KEY_RETURN;
KeyMap[AKEYCODE_BUTTON_SELECT] = IRR_KEY_BACK;
KeyMap[AKEYCODE_BUTTON_SELECT] = IRR_KEY_ESCAPE;
KeyMap[AKEYCODE_BUTTON_MODE] = IRR_KEY_MENU;
KeyMap[AKEYCODE_ESCAPE] = IRR_KEY_ESCAPE;