2013-04-20 04:52:54 +00:00
|
|
|
// Copyright (c) 2013- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2013-07-06 18:44:34 +00:00
|
|
|
#include "file/ini_file.h"
|
2013-04-20 04:52:54 +00:00
|
|
|
#include "input/input_state.h"
|
2013-07-03 18:37:31 +00:00
|
|
|
#include "../Core/Config.h"
|
2013-08-17 22:41:19 +00:00
|
|
|
#include "base/NativeApp.h"
|
2013-04-20 04:52:54 +00:00
|
|
|
#include "KeyMap.h"
|
2013-08-22 10:46:35 +00:00
|
|
|
#include "../Core/HLE/sceUtility.h"
|
2013-08-22 16:49:39 +00:00
|
|
|
|
2013-08-22 11:20:18 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2013-04-20 04:52:54 +00:00
|
|
|
|
2013-07-06 17:08:59 +00:00
|
|
|
namespace KeyMap {
|
2013-06-14 03:30:02 +00:00
|
|
|
|
2013-07-07 22:26:38 +00:00
|
|
|
KeyDef AxisDef(int deviceId, int axisId, int direction);
|
|
|
|
|
2013-08-16 19:25:01 +00:00
|
|
|
struct DefMappingStruct {
|
|
|
|
int pspKey;
|
|
|
|
int key;
|
|
|
|
int direction;
|
|
|
|
};
|
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
KeyMapping g_controllerMap;
|
|
|
|
|
2013-08-16 19:25:01 +00:00
|
|
|
static const DefMappingStruct defaultKeyboardKeyMap[] = {
|
2013-08-18 14:03:02 +00:00
|
|
|
#ifdef BLACKBERRY
|
|
|
|
{CTRL_SQUARE, NKCODE_J},
|
|
|
|
{CTRL_TRIANGLE, NKCODE_I},
|
|
|
|
{CTRL_CIRCLE, NKCODE_L},
|
|
|
|
{CTRL_CROSS, NKCODE_K},
|
|
|
|
#else
|
2013-08-16 19:25:01 +00:00
|
|
|
{CTRL_SQUARE, NKCODE_A},
|
|
|
|
{CTRL_TRIANGLE, NKCODE_S},
|
|
|
|
{CTRL_CIRCLE, NKCODE_X},
|
|
|
|
{CTRL_CROSS, NKCODE_Z},
|
2013-08-18 14:03:02 +00:00
|
|
|
#endif
|
2013-08-16 19:25:01 +00:00
|
|
|
{CTRL_LTRIGGER, NKCODE_Q},
|
|
|
|
{CTRL_RTRIGGER, NKCODE_W},
|
|
|
|
|
|
|
|
{CTRL_START, NKCODE_SPACE},
|
2013-07-05 09:04:39 +00:00
|
|
|
#ifdef _WIN32
|
2013-08-16 19:25:01 +00:00
|
|
|
{CTRL_SELECT, NKCODE_V},
|
2013-07-05 09:04:39 +00:00
|
|
|
#else
|
2013-08-16 19:25:01 +00:00
|
|
|
{CTRL_SELECT, NKCODE_ENTER},
|
2013-07-05 09:04:39 +00:00
|
|
|
#endif
|
2013-08-18 14:03:02 +00:00
|
|
|
#ifdef BLACKBERRY
|
|
|
|
{CTRL_UP , NKCODE_W},
|
|
|
|
{CTRL_DOWN , NKCODE_S},
|
|
|
|
{CTRL_LEFT , NKCODE_A},
|
|
|
|
{CTRL_RIGHT, NKCODE_D},
|
|
|
|
{VIRTKEY_AXIS_Y_MAX, NKCODE_W},
|
|
|
|
{VIRTKEY_AXIS_Y_MIN, NKCODE_S},
|
|
|
|
{VIRTKEY_AXIS_X_MIN, NKCODE_A},
|
|
|
|
{VIRTKEY_AXIS_X_MAX, NKCODE_D},
|
|
|
|
#else
|
2013-08-16 19:25:01 +00:00
|
|
|
{CTRL_UP , NKCODE_DPAD_UP},
|
|
|
|
{CTRL_DOWN , NKCODE_DPAD_DOWN},
|
|
|
|
{CTRL_LEFT , NKCODE_DPAD_LEFT},
|
|
|
|
{CTRL_RIGHT, NKCODE_DPAD_RIGHT},
|
|
|
|
{VIRTKEY_AXIS_Y_MAX, NKCODE_I},
|
|
|
|
{VIRTKEY_AXIS_Y_MIN, NKCODE_K},
|
|
|
|
{VIRTKEY_AXIS_X_MIN, NKCODE_J},
|
|
|
|
{VIRTKEY_AXIS_X_MAX, NKCODE_L},
|
2013-08-18 14:03:02 +00:00
|
|
|
#endif
|
2013-08-16 19:25:01 +00:00
|
|
|
{VIRTKEY_RAPID_FIRE , NKCODE_SHIFT_LEFT},
|
|
|
|
{VIRTKEY_UNTHROTTLE , NKCODE_TAB},
|
|
|
|
{VIRTKEY_SPEED_TOGGLE, NKCODE_GRAVE},
|
|
|
|
{VIRTKEY_PAUSE , NKCODE_ESCAPE},
|
|
|
|
};
|
2013-07-06 17:08:59 +00:00
|
|
|
|
2013-08-16 19:25:01 +00:00
|
|
|
static const DefMappingStruct default360KeyMap[] = {
|
2013-08-17 08:34:38 +00:00
|
|
|
{VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1},
|
|
|
|
{VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1},
|
|
|
|
{VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, -1},
|
|
|
|
{VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, +1},
|
2013-08-16 19:25:01 +00:00
|
|
|
{CTRL_CROSS , NKCODE_BUTTON_A},
|
|
|
|
{CTRL_CIRCLE , NKCODE_BUTTON_B},
|
|
|
|
{CTRL_SQUARE , NKCODE_BUTTON_X},
|
|
|
|
{CTRL_TRIANGLE , NKCODE_BUTTON_Y},
|
|
|
|
{CTRL_UP , NKCODE_DPAD_UP},
|
|
|
|
{CTRL_RIGHT , NKCODE_DPAD_RIGHT},
|
|
|
|
{CTRL_DOWN , NKCODE_DPAD_DOWN},
|
|
|
|
{CTRL_LEFT , NKCODE_DPAD_LEFT},
|
|
|
|
{CTRL_START , NKCODE_BUTTON_START},
|
|
|
|
{CTRL_SELECT , NKCODE_BUTTON_SELECT},
|
|
|
|
{CTRL_LTRIGGER , NKCODE_BUTTON_L1},
|
|
|
|
{CTRL_RTRIGGER , NKCODE_BUTTON_R1},
|
2013-08-17 09:18:45 +00:00
|
|
|
{VIRTKEY_UNTHROTTLE , JOYSTICK_AXIS_RTRIGGER, +1},
|
2013-08-18 09:47:11 +00:00
|
|
|
{VIRTKEY_SPEED_TOGGLE, NKCODE_BUTTON_THUMBR},
|
|
|
|
{VIRTKEY_PAUSE , JOYSTICK_AXIS_LTRIGGER, +1},
|
2013-08-17 09:18:45 +00:00
|
|
|
{VIRTKEY_PAUSE, NKCODE_HOME},
|
2013-08-16 19:25:01 +00:00
|
|
|
};
|
2013-07-06 17:08:59 +00:00
|
|
|
|
2013-08-16 19:25:01 +00:00
|
|
|
static const DefMappingStruct defaultShieldKeyMap[] = {
|
|
|
|
{CTRL_CROSS, NKCODE_BUTTON_A},
|
|
|
|
{CTRL_CIRCLE ,NKCODE_BUTTON_B},
|
|
|
|
{CTRL_SQUARE ,NKCODE_BUTTON_X},
|
|
|
|
{CTRL_TRIANGLE ,NKCODE_BUTTON_Y},
|
|
|
|
{CTRL_START, NKCODE_BUTTON_START},
|
2013-08-19 20:40:05 +00:00
|
|
|
{CTRL_SELECT, JOYSTICK_AXIS_LTRIGGER, +1},
|
2013-08-16 19:25:01 +00:00
|
|
|
{CTRL_LTRIGGER, NKCODE_BUTTON_L1},
|
|
|
|
{CTRL_RTRIGGER, NKCODE_BUTTON_R1},
|
|
|
|
{VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1},
|
|
|
|
{VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1},
|
2013-08-19 20:40:05 +00:00
|
|
|
{VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, +1},
|
|
|
|
{VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, -1},
|
2013-08-16 19:25:01 +00:00
|
|
|
{CTRL_LEFT, JOYSTICK_AXIS_HAT_X, -1},
|
|
|
|
{CTRL_RIGHT, JOYSTICK_AXIS_HAT_X, +1},
|
|
|
|
{CTRL_UP, JOYSTICK_AXIS_HAT_Y, -1},
|
|
|
|
{CTRL_DOWN, JOYSTICK_AXIS_HAT_Y, +1},
|
2013-08-19 20:40:05 +00:00
|
|
|
{VIRTKEY_UNTHROTTLE, JOYSTICK_AXIS_RTRIGGER, +1 },
|
2013-08-16 19:25:01 +00:00
|
|
|
{VIRTKEY_PAUSE, NKCODE_BACK },
|
|
|
|
};
|
2013-07-31 16:07:45 +00:00
|
|
|
|
2013-08-16 19:25:01 +00:00
|
|
|
static const DefMappingStruct defaultPadMap[] = {
|
2013-08-18 14:03:02 +00:00
|
|
|
#if defined(ANDROID) || defined(BLACKBERRY)
|
2013-08-16 19:25:01 +00:00
|
|
|
{CTRL_CROSS , NKCODE_BUTTON_A},
|
|
|
|
{CTRL_CIRCLE , NKCODE_BUTTON_B},
|
|
|
|
{CTRL_SQUARE , NKCODE_BUTTON_X},
|
|
|
|
{CTRL_TRIANGLE , NKCODE_BUTTON_Y},
|
|
|
|
{CTRL_UP , NKCODE_DPAD_UP},
|
|
|
|
{CTRL_RIGHT , NKCODE_DPAD_RIGHT},
|
|
|
|
{CTRL_DOWN , NKCODE_DPAD_DOWN},
|
|
|
|
{CTRL_LEFT , NKCODE_DPAD_LEFT},
|
|
|
|
{CTRL_START , NKCODE_BUTTON_START},
|
|
|
|
{CTRL_SELECT , NKCODE_BUTTON_SELECT},
|
|
|
|
{CTRL_LTRIGGER , NKCODE_BUTTON_L1},
|
|
|
|
{CTRL_RTRIGGER , NKCODE_BUTTON_R1},
|
|
|
|
{VIRTKEY_UNTHROTTLE , NKCODE_BUTTON_R2},
|
|
|
|
{VIRTKEY_PAUSE , NKCODE_BUTTON_THUMBR},
|
|
|
|
{VIRTKEY_SPEED_TOGGLE, NKCODE_BUTTON_L2},
|
|
|
|
{VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1},
|
|
|
|
{VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1},
|
2013-08-19 20:40:05 +00:00
|
|
|
{VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, +1},
|
|
|
|
{VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, -1},
|
2013-07-08 15:19:39 +00:00
|
|
|
#else
|
2013-08-16 19:25:01 +00:00
|
|
|
{CTRL_CROSS , NKCODE_BUTTON_2},
|
|
|
|
{CTRL_CIRCLE , NKCODE_BUTTON_3},
|
|
|
|
{CTRL_SQUARE , NKCODE_BUTTON_4},
|
|
|
|
{CTRL_TRIANGLE , NKCODE_BUTTON_1},
|
|
|
|
{CTRL_UP , NKCODE_DPAD_UP},
|
|
|
|
{CTRL_RIGHT , NKCODE_DPAD_RIGHT},
|
|
|
|
{CTRL_DOWN , NKCODE_DPAD_DOWN},
|
|
|
|
{CTRL_LEFT , NKCODE_DPAD_LEFT},
|
|
|
|
{CTRL_START , NKCODE_BUTTON_10},
|
|
|
|
{CTRL_SELECT , NKCODE_BUTTON_9},
|
|
|
|
{CTRL_LTRIGGER , NKCODE_BUTTON_7},
|
|
|
|
{CTRL_RTRIGGER , NKCODE_BUTTON_8},
|
|
|
|
{VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1},
|
|
|
|
{VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1},
|
|
|
|
{VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, +1},
|
|
|
|
{VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, -1},
|
2013-07-08 15:19:39 +00:00
|
|
|
#endif
|
2013-08-16 19:25:01 +00:00
|
|
|
};
|
2013-07-06 18:44:34 +00:00
|
|
|
|
2013-08-17 11:41:04 +00:00
|
|
|
static const DefMappingStruct defaultOuyaMap[] = {
|
|
|
|
{CTRL_CROSS , NKCODE_BUTTON_A},
|
|
|
|
{CTRL_CIRCLE , NKCODE_BUTTON_B},
|
|
|
|
{CTRL_SQUARE , NKCODE_BUTTON_X},
|
|
|
|
{CTRL_TRIANGLE , NKCODE_BUTTON_Y},
|
|
|
|
{CTRL_UP , NKCODE_DPAD_UP},
|
|
|
|
{CTRL_RIGHT , NKCODE_DPAD_RIGHT},
|
|
|
|
{CTRL_DOWN , NKCODE_DPAD_DOWN},
|
|
|
|
{CTRL_LEFT , NKCODE_DPAD_LEFT},
|
|
|
|
{CTRL_START , NKCODE_BUTTON_START},
|
|
|
|
{CTRL_SELECT , NKCODE_BUTTON_SELECT},
|
|
|
|
{CTRL_LTRIGGER , NKCODE_BUTTON_L1},
|
|
|
|
{CTRL_RTRIGGER , NKCODE_BUTTON_R1},
|
|
|
|
{VIRTKEY_UNTHROTTLE , NKCODE_BUTTON_R2},
|
|
|
|
{VIRTKEY_PAUSE , NKCODE_BUTTON_THUMBR},
|
|
|
|
{VIRTKEY_SPEED_TOGGLE, NKCODE_BUTTON_L2},
|
|
|
|
{VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1},
|
|
|
|
{VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1},
|
|
|
|
{VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, -1},
|
|
|
|
{VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, +1},
|
|
|
|
};
|
|
|
|
|
2013-08-16 19:25:01 +00:00
|
|
|
static const DefMappingStruct defaultXperiaPlay[] = {
|
|
|
|
{CTRL_CROSS , NKCODE_BUTTON_CROSS},
|
|
|
|
{CTRL_CIRCLE , NKCODE_BUTTON_CIRCLE},
|
|
|
|
{CTRL_SQUARE , NKCODE_BUTTON_X},
|
|
|
|
{CTRL_TRIANGLE , NKCODE_BUTTON_Y},
|
|
|
|
{CTRL_UP , NKCODE_DPAD_UP},
|
|
|
|
{CTRL_RIGHT , NKCODE_DPAD_RIGHT},
|
|
|
|
{CTRL_DOWN , NKCODE_DPAD_DOWN},
|
|
|
|
{CTRL_LEFT , NKCODE_DPAD_LEFT},
|
|
|
|
{CTRL_START , NKCODE_BUTTON_START},
|
2013-08-17 22:41:19 +00:00
|
|
|
{CTRL_SELECT , NKCODE_BUTTON_SELECT},
|
2013-08-16 19:25:01 +00:00
|
|
|
{CTRL_LTRIGGER , NKCODE_BUTTON_L1},
|
|
|
|
{CTRL_RTRIGGER , NKCODE_BUTTON_R1},
|
|
|
|
{VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1},
|
|
|
|
{VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1},
|
|
|
|
{VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, -1},
|
|
|
|
{VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, +1},
|
|
|
|
};
|
2013-07-06 18:44:34 +00:00
|
|
|
|
2013-08-22 10:46:35 +00:00
|
|
|
void UpdateConfirmCancelKeys() {
|
2013-08-22 11:20:18 +00:00
|
|
|
std::vector<keycode_t> confirmKeys, cancelKeys;
|
2013-08-22 10:46:35 +00:00
|
|
|
|
2013-08-22 11:20:18 +00:00
|
|
|
int confirmKey = g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CROSS : CTRL_CIRCLE;
|
|
|
|
int cancelKey = g_Config.iButtonPreference == PSP_SYSTEMPARAM_BUTTON_CROSS ? CTRL_CIRCLE : CTRL_CROSS;
|
2013-08-22 10:46:35 +00:00
|
|
|
|
2013-08-22 11:20:18 +00:00
|
|
|
for(auto i = g_controllerMap[confirmKey].begin(); i != g_controllerMap[confirmKey].end(); ++i) {
|
|
|
|
confirmKeys.push_back((keycode_t)i->keyCode);
|
2013-08-22 10:46:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-22 11:20:18 +00:00
|
|
|
for(auto i = g_controllerMap[cancelKey].begin(); i != g_controllerMap[cancelKey].end(); ++i) {
|
|
|
|
cancelKeys.push_back((keycode_t)i->keyCode);
|
2013-08-22 10:46:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-22 16:38:04 +00:00
|
|
|
// Push several hard-coded keys before submitting to native.
|
2013-08-22 17:06:12 +00:00
|
|
|
const keycode_t hardcodedConfirmKeys[] = {
|
|
|
|
NKCODE_SPACE,
|
|
|
|
NKCODE_ENTER,
|
|
|
|
};
|
|
|
|
|
|
|
|
// If they're not already bound, add them in.
|
|
|
|
for(int i = 0; i < ARRAY_SIZE(hardcodedConfirmKeys); i++) {
|
|
|
|
if(std::find(confirmKeys.begin(), confirmKeys.end(), hardcodedConfirmKeys[i]) == confirmKeys.end())
|
|
|
|
confirmKeys.push_back(hardcodedConfirmKeys[i]);
|
|
|
|
}
|
2013-08-22 16:38:04 +00:00
|
|
|
|
2013-08-22 11:20:18 +00:00
|
|
|
const keycode_t hardcodedCancelKeys[] = {
|
|
|
|
NKCODE_ESCAPE,
|
|
|
|
NKCODE_BACK,
|
|
|
|
};
|
|
|
|
|
|
|
|
for(int i = 0; i < ARRAY_SIZE(hardcodedCancelKeys); i++) {
|
|
|
|
if(std::find(cancelKeys.begin(), cancelKeys.end(), hardcodedCancelKeys[i]) == cancelKeys.end())
|
|
|
|
cancelKeys.push_back(hardcodedCancelKeys[i]);
|
|
|
|
}
|
2013-08-22 10:46:35 +00:00
|
|
|
|
2013-08-22 11:20:18 +00:00
|
|
|
SetConfirmCancelKeys(confirmKeys,cancelKeys);
|
2013-08-22 10:46:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
static void SetDefaultKeyMap(int deviceId, const DefMappingStruct *array, int count, bool replace) {
|
2013-08-16 19:25:01 +00:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
|
|
|
if (array[i].direction == 0)
|
|
|
|
SetKeyMapping(array[i].pspKey, KeyDef(deviceId, array[i].key), replace);
|
|
|
|
else
|
|
|
|
SetAxisMapping(array[i].pspKey, deviceId, array[i].key, array[i].direction, replace);
|
2013-07-06 17:08:59 +00:00
|
|
|
}
|
2013-08-16 19:25:01 +00:00
|
|
|
}
|
2013-07-06 17:08:59 +00:00
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
void SetDefaultKeyMap(DefaultMaps dmap, bool replace) {
|
2013-08-16 19:25:01 +00:00
|
|
|
switch (dmap) {
|
|
|
|
case DEFAULT_MAPPING_KEYBOARD:
|
2013-08-17 08:34:38 +00:00
|
|
|
SetDefaultKeyMap(DEVICE_ID_KEYBOARD, defaultKeyboardKeyMap, ARRAY_SIZE(defaultKeyboardKeyMap), replace);
|
2013-08-16 19:25:01 +00:00
|
|
|
break;
|
|
|
|
case DEFAULT_MAPPING_X360:
|
2013-08-17 08:34:38 +00:00
|
|
|
SetDefaultKeyMap(DEVICE_ID_X360_0, default360KeyMap, ARRAY_SIZE(default360KeyMap), replace);
|
2013-08-16 19:25:01 +00:00
|
|
|
break;
|
|
|
|
case DEFAULT_MAPPING_SHIELD:
|
2013-08-17 22:41:19 +00:00
|
|
|
SetDefaultKeyMap(DEVICE_ID_PAD_0, defaultShieldKeyMap, ARRAY_SIZE(defaultShieldKeyMap), replace);
|
2013-08-16 19:25:01 +00:00
|
|
|
break;
|
2013-08-17 11:41:04 +00:00
|
|
|
case DEFAULT_MAPPING_PAD:
|
2013-08-17 22:41:19 +00:00
|
|
|
SetDefaultKeyMap(DEVICE_ID_PAD_0, defaultPadMap, ARRAY_SIZE(defaultPadMap), replace);
|
2013-08-17 11:41:04 +00:00
|
|
|
break;
|
|
|
|
case DEFAULT_MAPPING_OUYA:
|
2013-08-17 22:41:19 +00:00
|
|
|
SetDefaultKeyMap(DEVICE_ID_PAD_0, defaultOuyaMap, ARRAY_SIZE(defaultOuyaMap), replace);
|
2013-08-17 11:41:04 +00:00
|
|
|
break;
|
|
|
|
case DEFAULT_MAPPING_XPERIA_PLAY:
|
2013-08-17 22:41:19 +00:00
|
|
|
SetDefaultKeyMap(DEVICE_ID_DEFAULT, defaultXperiaPlay, ARRAY_SIZE(defaultXperiaPlay), replace);
|
2013-08-17 11:41:04 +00:00
|
|
|
break;
|
2013-08-16 19:25:01 +00:00
|
|
|
}
|
2013-08-22 10:46:35 +00:00
|
|
|
|
|
|
|
UpdateConfirmCancelKeys();
|
2013-08-16 19:25:01 +00:00
|
|
|
}
|
2013-08-16 17:34:44 +00:00
|
|
|
|
2013-06-14 03:30:02 +00:00
|
|
|
const KeyMap_IntStrPair key_names[] = {
|
2013-08-04 17:31:40 +00:00
|
|
|
{NKCODE_A, "A"},
|
|
|
|
{NKCODE_B, "B"},
|
|
|
|
{NKCODE_C, "C"},
|
|
|
|
{NKCODE_D, "D"},
|
|
|
|
{NKCODE_E, "E"},
|
|
|
|
{NKCODE_F, "F"},
|
|
|
|
{NKCODE_G, "G"},
|
|
|
|
{NKCODE_H, "H"},
|
|
|
|
{NKCODE_I, "I"},
|
|
|
|
{NKCODE_J, "J"},
|
|
|
|
{NKCODE_K, "K"},
|
|
|
|
{NKCODE_L, "L"},
|
|
|
|
{NKCODE_M, "M"},
|
|
|
|
{NKCODE_N, "N"},
|
|
|
|
{NKCODE_O, "O"},
|
|
|
|
{NKCODE_P, "P"},
|
|
|
|
{NKCODE_Q, "Q"},
|
|
|
|
{NKCODE_R, "R"},
|
|
|
|
{NKCODE_S, "S"},
|
|
|
|
{NKCODE_T, "T"},
|
|
|
|
{NKCODE_U, "U"},
|
|
|
|
{NKCODE_V, "V"},
|
|
|
|
{NKCODE_W, "W"},
|
|
|
|
{NKCODE_X, "X"},
|
|
|
|
{NKCODE_Y, "Y"},
|
|
|
|
{NKCODE_Z, "Z"},
|
|
|
|
|
|
|
|
{NKCODE_0, "0"},
|
|
|
|
{NKCODE_1, "1"},
|
|
|
|
{NKCODE_2, "2"},
|
|
|
|
{NKCODE_3, "3"},
|
|
|
|
{NKCODE_4, "4"},
|
|
|
|
{NKCODE_5, "5"},
|
|
|
|
{NKCODE_6, "6"},
|
|
|
|
{NKCODE_7, "7"},
|
|
|
|
{NKCODE_8, "8"},
|
|
|
|
{NKCODE_9, "9"},
|
|
|
|
|
|
|
|
{NKCODE_F1, "F1"},
|
|
|
|
{NKCODE_F2, "F2"},
|
|
|
|
{NKCODE_F3, "F3"},
|
|
|
|
{NKCODE_F4, "F4"},
|
|
|
|
{NKCODE_F5, "F5"},
|
|
|
|
{NKCODE_F6, "F6"},
|
|
|
|
{NKCODE_F7, "F7"},
|
|
|
|
{NKCODE_F8, "F8"},
|
|
|
|
{NKCODE_F9, "F9"},
|
|
|
|
{NKCODE_F10, "F10"},
|
|
|
|
{NKCODE_F11, "F11"},
|
|
|
|
{NKCODE_F12, "F12"},
|
2013-07-06 17:08:59 +00:00
|
|
|
|
2013-08-04 17:31:40 +00:00
|
|
|
{NKCODE_GRAVE, "`"},
|
|
|
|
{NKCODE_SLASH, "/"},
|
|
|
|
{NKCODE_BACKSLASH, "\\"},
|
|
|
|
{NKCODE_SEMICOLON, ";"},
|
|
|
|
{NKCODE_COMMA, ","},
|
|
|
|
{NKCODE_PERIOD, "."},
|
|
|
|
{NKCODE_LEFT_BRACKET, "["},
|
|
|
|
{NKCODE_RIGHT_BRACKET, "]"},
|
|
|
|
{NKCODE_APOSTROPHE, "'"},
|
|
|
|
{NKCODE_MINUS, "-"},
|
|
|
|
{NKCODE_PLUS, "+"},
|
|
|
|
{NKCODE_SYSRQ, "Print"},
|
|
|
|
{NKCODE_SCROLL_LOCK, "ScrLock"},
|
|
|
|
{NKCODE_BREAK, "Pause"},
|
|
|
|
|
|
|
|
{NKCODE_BACK, "Back"},
|
|
|
|
{NKCODE_TAB, "Tab"},
|
|
|
|
{NKCODE_ENTER, "Enter"},
|
|
|
|
{NKCODE_SHIFT_LEFT, "LShift"},
|
|
|
|
{NKCODE_SHIFT_RIGHT, "RShift"},
|
|
|
|
{NKCODE_CTRL_LEFT, "LCtrl"},
|
|
|
|
{NKCODE_CTRL_RIGHT, "RCtrl"},
|
|
|
|
{NKCODE_ALT_LEFT, "LAlt"},
|
|
|
|
{NKCODE_ALT_RIGHT, "RAlt"},
|
|
|
|
{NKCODE_SPACE, "Space"},
|
|
|
|
{NKCODE_WINDOW, "Windows"},
|
|
|
|
{NKCODE_DEL, "Del"},
|
|
|
|
{NKCODE_MOVE_HOME, "Home"},
|
|
|
|
{NKCODE_MOVE_END, "End"},
|
|
|
|
{NKCODE_ESCAPE, "Esc"},
|
|
|
|
{NKCODE_CAPS_LOCK, "CapsLock"},
|
|
|
|
|
|
|
|
{NKCODE_VOLUME_UP, "Vol +"},
|
|
|
|
{NKCODE_VOLUME_DOWN, "Vol -"},
|
|
|
|
{NKCODE_HOME, "Home"},
|
|
|
|
{NKCODE_INSERT, "Ins"},
|
|
|
|
{NKCODE_PAGE_UP, "PgUp"},
|
|
|
|
{NKCODE_PAGE_DOWN, "PgDn"},
|
|
|
|
{NKCODE_CLEAR, "Clear"}, // 5 when numlock off
|
|
|
|
{NKCODE_CALL, "Call"},
|
|
|
|
{NKCODE_ENDCALL, "End Call"},
|
|
|
|
|
|
|
|
{NKCODE_DPAD_LEFT, "Left"},
|
|
|
|
{NKCODE_DPAD_UP, "Up"},
|
|
|
|
{NKCODE_DPAD_RIGHT, "Right"},
|
|
|
|
{NKCODE_DPAD_DOWN, "Down"},
|
|
|
|
|
|
|
|
{NKCODE_BUTTON_L1, "L1"},
|
|
|
|
{NKCODE_BUTTON_L2, "L2"},
|
|
|
|
{NKCODE_BUTTON_R1, "R1"},
|
|
|
|
{NKCODE_BUTTON_R2, "R2"},
|
|
|
|
|
|
|
|
{NKCODE_BUTTON_A, "[A]"},
|
|
|
|
{NKCODE_BUTTON_B, "[B]"},
|
|
|
|
{NKCODE_BUTTON_C, "[C]"},
|
|
|
|
{NKCODE_BUTTON_X, "[X]"},
|
|
|
|
{NKCODE_BUTTON_Y, "[Y]"},
|
|
|
|
{NKCODE_BUTTON_Z, "[Z]"},
|
|
|
|
{NKCODE_BUTTON_1, "b1"},
|
|
|
|
{NKCODE_BUTTON_2, "b2"},
|
|
|
|
{NKCODE_BUTTON_3, "b3"},
|
|
|
|
{NKCODE_BUTTON_4, "b4"},
|
|
|
|
{NKCODE_BUTTON_5, "b5"},
|
|
|
|
{NKCODE_BUTTON_6, "b6"},
|
|
|
|
{NKCODE_BUTTON_7, "b7"},
|
|
|
|
{NKCODE_BUTTON_8, "b8"},
|
|
|
|
{NKCODE_BUTTON_9, "b9"},
|
|
|
|
{NKCODE_BUTTON_10, "b10"},
|
|
|
|
{NKCODE_BUTTON_11, "b11"},
|
|
|
|
{NKCODE_BUTTON_12, "b12"},
|
|
|
|
{NKCODE_BUTTON_13, "b13"},
|
|
|
|
{NKCODE_BUTTON_14, "b14"},
|
|
|
|
{NKCODE_BUTTON_15, "b15"},
|
|
|
|
{NKCODE_BUTTON_16, "b16"},
|
|
|
|
{NKCODE_BUTTON_START, "Start"},
|
|
|
|
{NKCODE_BUTTON_SELECT, "Select"},
|
|
|
|
{NKCODE_BUTTON_CIRCLE, "Circle"},
|
|
|
|
{NKCODE_BUTTON_CIRCLE_PS3, "Circle3"},
|
|
|
|
{NKCODE_BUTTON_CROSS, "Cross"},
|
|
|
|
{NKCODE_BUTTON_CROSS_PS3, "Cross3"},
|
|
|
|
{NKCODE_BUTTON_TRIANGLE, "Triangle"},
|
|
|
|
{NKCODE_BUTTON_SQUARE, "Square"},
|
|
|
|
{NKCODE_BUTTON_THUMBL, "ThumbL"},
|
|
|
|
{NKCODE_BUTTON_THUMBR, "ThumbR"},
|
|
|
|
{NKCODE_BUTTON_MODE, "Mode"},
|
|
|
|
|
|
|
|
{NKCODE_EXT_PIPE, "|"},
|
|
|
|
{NKCODE_NUMPAD_DIVIDE, "Num/"},
|
|
|
|
{NKCODE_NUMPAD_MULTIPLY, "Num*"},
|
|
|
|
{NKCODE_NUMPAD_ADD, "Num+"},
|
|
|
|
{NKCODE_NUMPAD_SUBTRACT, "Num-"},
|
|
|
|
{NKCODE_NUMPAD_DOT, "Num."},
|
|
|
|
{NKCODE_NUMPAD_COMMA, "Num,"},
|
|
|
|
{NKCODE_NUMPAD_ENTER, "NumEnter"},
|
|
|
|
{NKCODE_NUMPAD_EQUALS, "Num="},
|
|
|
|
{NKCODE_NUMPAD_LEFT_PAREN, "Num("},
|
|
|
|
{NKCODE_NUMPAD_RIGHT_PAREN, "Num)"},
|
|
|
|
{NKCODE_NUMPAD_0, "Num0"},
|
|
|
|
{NKCODE_NUMPAD_1, "Num1"},
|
|
|
|
{NKCODE_NUMPAD_2, "Num2"},
|
|
|
|
{NKCODE_NUMPAD_3, "Num3"},
|
|
|
|
{NKCODE_NUMPAD_4, "Num4"},
|
|
|
|
{NKCODE_NUMPAD_5, "Num5"},
|
|
|
|
{NKCODE_NUMPAD_6, "Num6"},
|
|
|
|
{NKCODE_NUMPAD_7, "Num7"},
|
|
|
|
{NKCODE_NUMPAD_8, "Num8"},
|
|
|
|
{NKCODE_NUMPAD_9, "Num9"},
|
|
|
|
|
|
|
|
{NKCODE_EXT_MOUSEBUTTON_1, "MB1"},
|
|
|
|
{NKCODE_EXT_MOUSEBUTTON_2, "MB2"},
|
|
|
|
{NKCODE_EXT_MOUSEBUTTON_3, "MB3"},
|
|
|
|
{NKCODE_EXT_MOUSEWHEEL_UP, "MWheelU"},
|
|
|
|
{NKCODE_EXT_MOUSEWHEEL_DOWN, "MWheelD"},
|
2013-06-14 03:30:02 +00:00
|
|
|
};
|
2013-07-06 17:08:59 +00:00
|
|
|
|
2013-07-07 22:21:40 +00:00
|
|
|
const KeyMap_IntStrPair axis_names[] = {
|
|
|
|
{JOYSTICK_AXIS_X, "X Axis"},
|
|
|
|
{JOYSTICK_AXIS_Y, "Y Axis"},
|
|
|
|
{JOYSTICK_AXIS_PRESSURE, "Pressure"},
|
|
|
|
{JOYSTICK_AXIS_SIZE, "Size"},
|
|
|
|
{JOYSTICK_AXIS_TOUCH_MAJOR, "Touch Major"},
|
|
|
|
{JOYSTICK_AXIS_TOUCH_MINOR, "Touch Minor"},
|
|
|
|
{JOYSTICK_AXIS_TOOL_MAJOR, "Tool Major"},
|
|
|
|
{JOYSTICK_AXIS_TOOL_MINOR, "Tool Minor"},
|
|
|
|
{JOYSTICK_AXIS_ORIENTATION, "Orient"},
|
|
|
|
{JOYSTICK_AXIS_VSCROLL, "Vert Scroll"},
|
|
|
|
{JOYSTICK_AXIS_HSCROLL, "Horiz Scroll"},
|
2013-07-08 10:35:08 +00:00
|
|
|
{JOYSTICK_AXIS_Z, "Z Axis"}, // Also used as second stick X on many controllers - rename?
|
2013-07-07 22:21:40 +00:00
|
|
|
{JOYSTICK_AXIS_RX, "X Rotation"},
|
|
|
|
{JOYSTICK_AXIS_RY, "Y Rotation"},
|
2013-07-08 10:35:08 +00:00
|
|
|
{JOYSTICK_AXIS_RZ, "Z Rotation"}, // Also used as second stick Y on many controllers - rename?
|
2013-07-07 22:21:40 +00:00
|
|
|
{JOYSTICK_AXIS_HAT_X, "X HAT"},
|
|
|
|
{JOYSTICK_AXIS_HAT_Y, "Y HAT"},
|
|
|
|
{JOYSTICK_AXIS_LTRIGGER, "TriggerL"},
|
|
|
|
{JOYSTICK_AXIS_RTRIGGER, "TriggerR"},
|
|
|
|
{JOYSTICK_AXIS_THROTTLE, "Throttle"},
|
|
|
|
{JOYSTICK_AXIS_RUDDER, "Rudder"},
|
|
|
|
{JOYSTICK_AXIS_WHEEL, "Wheel"},
|
|
|
|
{JOYSTICK_AXIS_GAS, "Gas"},
|
|
|
|
{JOYSTICK_AXIS_BRAKE, "Brake"},
|
|
|
|
{JOYSTICK_AXIS_DISTANCE, "Distance"},
|
2013-08-12 21:26:01 +00:00
|
|
|
{JOYSTICK_AXIS_TILT, "Tilt"},
|
|
|
|
{JOYSTICK_AXIS_MOUSE_REL_X, "MouseDX"},
|
|
|
|
{JOYSTICK_AXIS_MOUSE_REL_Y, "MouseDY"},
|
2013-08-16 14:48:43 +00:00
|
|
|
{JOYSTICK_AXIS_ACCELEROMETER_X, "AccelX"},
|
|
|
|
{JOYSTICK_AXIS_ACCELEROMETER_Y, "AccelY"},
|
|
|
|
{JOYSTICK_AXIS_ACCELEROMETER_Z, "AccelZ"},
|
2013-07-07 22:21:40 +00:00
|
|
|
};
|
|
|
|
|
2013-07-07 12:37:58 +00:00
|
|
|
static std::string unknown_key_name = "??";
|
2013-08-16 17:34:44 +00:00
|
|
|
|
2013-06-14 03:30:02 +00:00
|
|
|
const KeyMap_IntStrPair psp_button_names[] = {
|
2013-08-17 09:18:45 +00:00
|
|
|
{CTRL_UP, "Up"},
|
|
|
|
{CTRL_DOWN, "Down"},
|
|
|
|
{CTRL_LEFT, "Left"},
|
|
|
|
{CTRL_RIGHT, "Right"},
|
2013-08-16 19:25:01 +00:00
|
|
|
{CTRL_CIRCLE, "Circle"},
|
|
|
|
{CTRL_CROSS, "Cross"},
|
|
|
|
{CTRL_SQUARE, "Square"},
|
|
|
|
{CTRL_TRIANGLE, "Triangle"},
|
2013-06-25 05:08:23 +00:00
|
|
|
{CTRL_START, "Start"},
|
|
|
|
{CTRL_SELECT, "Select"},
|
2013-08-17 09:18:45 +00:00
|
|
|
{CTRL_LTRIGGER, "L"},
|
|
|
|
{CTRL_RTRIGGER, "R"},
|
2013-07-06 18:44:34 +00:00
|
|
|
|
2013-08-17 09:47:56 +00:00
|
|
|
{VIRTKEY_AXIS_Y_MAX, "An.Up"},
|
|
|
|
{VIRTKEY_AXIS_Y_MIN, "An.Down"},
|
2013-07-06 18:44:34 +00:00
|
|
|
{VIRTKEY_AXIS_X_MIN, "An.Left"},
|
|
|
|
{VIRTKEY_AXIS_X_MAX, "An.Right"},
|
2013-07-07 09:24:51 +00:00
|
|
|
|
|
|
|
{VIRTKEY_RAPID_FIRE, "RapidFire"},
|
|
|
|
{VIRTKEY_UNTHROTTLE, "Unthrottle"},
|
2013-07-07 12:08:08 +00:00
|
|
|
{VIRTKEY_SPEED_TOGGLE, "SpeedToggle"},
|
|
|
|
{VIRTKEY_PAUSE, "Pause"},
|
2013-08-17 09:18:45 +00:00
|
|
|
|
2013-08-17 09:47:56 +00:00
|
|
|
{VIRTKEY_AXIS_RIGHT_Y_MAX, "RightAn.Up"},
|
|
|
|
{VIRTKEY_AXIS_RIGHT_Y_MIN, "RightAn.Down"},
|
2013-08-17 09:18:45 +00:00
|
|
|
{VIRTKEY_AXIS_RIGHT_X_MIN, "RightAn.Left"},
|
|
|
|
{VIRTKEY_AXIS_RIGHT_X_MAX, "RightAn.Right"},
|
2013-06-14 03:30:02 +00:00
|
|
|
};
|
2013-07-06 18:44:34 +00:00
|
|
|
|
2013-08-04 17:31:40 +00:00
|
|
|
const int AXIS_BIND_NKCODE_START = 4000;
|
2013-06-14 03:30:02 +00:00
|
|
|
|
2013-08-16 17:34:44 +00:00
|
|
|
static std::string FindName(int key, const KeyMap_IntStrPair list[], size_t size) {
|
2013-07-07 22:21:40 +00:00
|
|
|
for (size_t i = 0; i < size; i++)
|
2013-06-14 03:30:02 +00:00
|
|
|
if (list[i].key == key)
|
|
|
|
return list[i].name;
|
|
|
|
|
|
|
|
return unknown_key_name;
|
|
|
|
}
|
2013-04-20 04:52:54 +00:00
|
|
|
|
2013-08-16 17:34:44 +00:00
|
|
|
std::string GetKeyName(int keyCode) {
|
2013-07-07 22:21:40 +00:00
|
|
|
return FindName(keyCode, key_names, ARRAY_SIZE(key_names));
|
2013-06-14 03:30:02 +00:00
|
|
|
}
|
2013-04-20 04:52:54 +00:00
|
|
|
|
2013-08-17 09:18:45 +00:00
|
|
|
std::string GetKeyOrAxisName(int keyCode) {
|
|
|
|
if (keyCode >= AXIS_BIND_NKCODE_START) {
|
|
|
|
int direction;
|
|
|
|
int axis = TranslateKeyCodeToAxis(keyCode, direction);
|
|
|
|
std::string temp = GetAxisName(axis);
|
|
|
|
if (direction == 1)
|
|
|
|
temp += "+";
|
|
|
|
else if (direction == -1)
|
|
|
|
temp += "-";
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
return FindName(keyCode, key_names, ARRAY_SIZE(key_names));
|
|
|
|
}
|
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
std::string GetAxisName(int axisId) {
|
|
|
|
return FindName(axisId, axis_names, ARRAY_SIZE(axis_names));
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:34:44 +00:00
|
|
|
std::string GetPspButtonName(int btn) {
|
2013-07-07 22:21:40 +00:00
|
|
|
return FindName(btn, psp_button_names, ARRAY_SIZE(psp_button_names));
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:34:44 +00:00
|
|
|
std::vector<KeyMap_IntStrPair> GetMappableKeys() {
|
|
|
|
std::vector<KeyMap_IntStrPair> temp;
|
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++) {
|
|
|
|
temp.push_back(psp_button_names[i]);
|
|
|
|
}
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TranslateKeyCodeToAxis(int keyCode, int &direction) {
|
2013-08-04 17:31:40 +00:00
|
|
|
if (keyCode < AXIS_BIND_NKCODE_START)
|
2013-07-07 22:21:40 +00:00
|
|
|
return 0;
|
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
int v = keyCode - AXIS_BIND_NKCODE_START;
|
2013-07-07 22:21:40 +00:00
|
|
|
// Even/odd for direction.
|
|
|
|
direction = v & 1 ? -1 : 1;
|
|
|
|
return v / 2;
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:34:44 +00:00
|
|
|
int TranslateKeyCodeFromAxis(int axisId, int direction) {
|
2013-07-07 22:21:40 +00:00
|
|
|
direction = direction < 0 ? 1 : 0;
|
2013-08-04 17:31:40 +00:00
|
|
|
return AXIS_BIND_NKCODE_START + axisId * 2 + direction;
|
2013-06-14 03:30:02 +00:00
|
|
|
}
|
2013-04-20 04:52:54 +00:00
|
|
|
|
2013-07-07 22:26:38 +00:00
|
|
|
KeyDef AxisDef(int deviceId, int axisId, int direction) {
|
|
|
|
return KeyDef(deviceId, TranslateKeyCodeFromAxis(axisId, direction));
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:34:44 +00:00
|
|
|
static bool FindKeyMapping(int deviceId, int key, int *psp_button) {
|
|
|
|
// Brute force, let's optimize later
|
2013-08-17 08:34:38 +00:00
|
|
|
for (auto iter = g_controllerMap.begin(); iter != g_controllerMap.end(); ++iter) {
|
2013-08-16 19:25:01 +00:00
|
|
|
for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2) {
|
|
|
|
if (*iter2 == KeyDef(deviceId, key)) {
|
|
|
|
*psp_button = iter->first;
|
|
|
|
return true;
|
|
|
|
}
|
2013-04-20 04:52:54 +00:00
|
|
|
}
|
2013-06-14 03:30:02 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-20 04:52:54 +00:00
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
int KeyToPspButton(int deviceId, int key) {
|
2013-06-14 03:30:02 +00:00
|
|
|
int search_start_layer = 0;
|
|
|
|
int psp_button;
|
2013-04-20 04:52:54 +00:00
|
|
|
|
2013-07-06 17:08:59 +00:00
|
|
|
if (FindKeyMapping(deviceId, key, &psp_button))
|
2013-06-14 03:30:02 +00:00
|
|
|
return psp_button;
|
2013-04-20 04:52:54 +00:00
|
|
|
|
2013-06-14 03:30:02 +00:00
|
|
|
return KEYMAP_ERROR_UNKNOWN_KEY;
|
|
|
|
}
|
2013-04-20 04:52:54 +00:00
|
|
|
|
2013-08-16 17:34:44 +00:00
|
|
|
// TODO: vector output
|
2013-08-17 08:34:38 +00:00
|
|
|
bool KeyFromPspButton(int btn, std::vector<KeyDef> *keys) {
|
2013-07-06 17:08:59 +00:00
|
|
|
int search_start_layer = 0;
|
2013-04-20 04:52:54 +00:00
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
for (auto iter = g_controllerMap.begin(); iter != g_controllerMap.end(); ++iter) {
|
2013-08-16 17:34:44 +00:00
|
|
|
if (iter->first == btn) {
|
2013-08-16 19:25:01 +00:00
|
|
|
for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2) {
|
2013-08-17 08:34:38 +00:00
|
|
|
keys->push_back(*iter2);
|
2013-08-16 19:25:01 +00:00
|
|
|
}
|
2013-07-06 17:08:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-20 04:52:54 +00:00
|
|
|
|
2013-08-16 17:34:44 +00:00
|
|
|
int AxisToPspButton(int deviceId, int axisId, int direction) {
|
2013-07-07 22:21:40 +00:00
|
|
|
int key = TranslateKeyCodeFromAxis(axisId, direction);
|
|
|
|
return KeyToPspButton(deviceId, key);
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:34:44 +00:00
|
|
|
bool AxisFromPspButton(int btn, int *deviceId, int *axisId, int *direction) {
|
2013-07-07 22:21:40 +00:00
|
|
|
int search_start_layer = 0;
|
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
for (auto iter = g_controllerMap.begin(); iter != g_controllerMap.end(); ++iter) {
|
2013-08-16 19:25:01 +00:00
|
|
|
for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2) {
|
|
|
|
if (iter->first == btn && iter2->keyCode >= AXIS_BIND_NKCODE_START) {
|
|
|
|
*deviceId = iter2->deviceId;
|
|
|
|
*axisId = TranslateKeyCodeToAxis(iter2->keyCode, *direction);
|
|
|
|
return true;
|
|
|
|
}
|
2013-07-07 22:21:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:34:44 +00:00
|
|
|
void RemoveButtonMapping(int btn) {
|
2013-08-17 08:34:38 +00:00
|
|
|
for (auto iter = g_controllerMap.begin(); iter != g_controllerMap.end(); ++iter) {
|
2013-08-16 17:34:44 +00:00
|
|
|
if (iter->first == btn) {
|
2013-08-17 08:34:38 +00:00
|
|
|
g_controllerMap.erase(iter);
|
2013-07-06 18:44:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-16 19:25:01 +00:00
|
|
|
void SetKeyMapping(int btn, KeyDef key, bool replace) {
|
2013-08-17 08:34:38 +00:00
|
|
|
if (key.keyCode < 0)
|
|
|
|
return;
|
2013-08-16 19:25:01 +00:00
|
|
|
if (replace) {
|
|
|
|
RemoveButtonMapping(btn);
|
2013-08-17 08:34:38 +00:00
|
|
|
g_controllerMap[btn].clear();
|
|
|
|
g_controllerMap[btn].push_back(key);
|
2013-08-16 19:25:01 +00:00
|
|
|
} else {
|
2013-08-17 08:34:38 +00:00
|
|
|
for (auto iter = g_controllerMap[btn].begin(); iter != g_controllerMap[btn].end(); ++iter) {
|
2013-08-16 19:25:01 +00:00
|
|
|
if (*iter == key)
|
|
|
|
return;
|
|
|
|
}
|
2013-08-17 08:34:38 +00:00
|
|
|
g_controllerMap[btn].push_back(key);
|
2013-08-16 19:25:01 +00:00
|
|
|
}
|
2013-08-22 10:46:35 +00:00
|
|
|
|
|
|
|
UpdateConfirmCancelKeys();
|
2013-07-06 18:44:34 +00:00
|
|
|
}
|
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
void SetAxisMapping(int btn, int deviceId, int axisId, int direction, bool replace) {
|
2013-07-07 22:21:40 +00:00
|
|
|
int key = TranslateKeyCodeFromAxis(axisId, direction);
|
2013-08-16 19:25:01 +00:00
|
|
|
SetKeyMapping(btn, KeyDef(deviceId, key), replace);
|
2013-07-07 22:21:40 +00:00
|
|
|
}
|
|
|
|
|
2013-08-16 19:25:01 +00:00
|
|
|
// Note that it's easy to add other defaults if desired.
|
2013-07-07 09:14:46 +00:00
|
|
|
void RestoreDefault() {
|
2013-08-20 14:06:43 +00:00
|
|
|
g_controllerMap.clear();
|
2013-08-16 19:25:01 +00:00
|
|
|
#if defined(_WIN32)
|
2013-08-17 08:34:38 +00:00
|
|
|
SetDefaultKeyMap(DEFAULT_MAPPING_KEYBOARD, true);
|
|
|
|
SetDefaultKeyMap(DEFAULT_MAPPING_X360, false);
|
2013-08-20 07:34:30 +00:00
|
|
|
SetDefaultKeyMap(DEFAULT_MAPPING_PAD, false);
|
2013-08-16 19:25:01 +00:00
|
|
|
#elif defined(ANDROID)
|
2013-08-17 22:41:19 +00:00
|
|
|
// Autodetect a few common devices
|
|
|
|
std::string name = System_GetName();
|
|
|
|
if (name == "NVIDIA:SHIELD") {
|
|
|
|
SetDefaultKeyMap(DEFAULT_MAPPING_SHIELD, true);
|
|
|
|
} else if (name == "OUYA:OUYA") { // TODO: check!
|
|
|
|
SetDefaultKeyMap(DEFAULT_MAPPING_OUYA, true);
|
|
|
|
} else if (name == "Sony Ericsson:R800i" || name == "Sony Ericsson:zeus") {
|
|
|
|
SetDefaultKeyMap(DEFAULT_MAPPING_XPERIA_PLAY, true);
|
2013-08-20 14:06:43 +00:00
|
|
|
} else {
|
|
|
|
SetDefaultKeyMap(DEFAULT_MAPPING_PAD, true);
|
2013-08-17 22:41:19 +00:00
|
|
|
}
|
2013-08-16 19:25:01 +00:00
|
|
|
#else
|
2013-08-17 08:34:38 +00:00
|
|
|
SetDefaultKeyMap(DEFAULT_MAPPING_KEYBOARD, true);
|
|
|
|
SetDefaultKeyMap(DEFAULT_MAPPING_PAD, false);
|
2013-08-16 19:25:01 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-07-06 18:44:34 +00:00
|
|
|
// TODO: Make the ini format nicer.
|
|
|
|
void LoadFromIni(IniFile &file) {
|
2013-08-16 19:25:01 +00:00
|
|
|
RestoreDefault();
|
2013-07-06 18:44:34 +00:00
|
|
|
if (!file.HasSection("ControlMapping")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IniFile::Section *controls = file.GetOrCreateSection("ControlMapping");
|
2013-08-16 19:25:01 +00:00
|
|
|
for (int i = 0; i < ARRAY_SIZE(psp_button_names); i++) {
|
|
|
|
std::string value;
|
|
|
|
controls->Get(psp_button_names[i].name.c_str(), &value, "");
|
2013-08-17 23:04:49 +00:00
|
|
|
|
2013-08-16 19:25:01 +00:00
|
|
|
// Erase default mapping
|
2013-08-17 08:34:38 +00:00
|
|
|
g_controllerMap.erase(psp_button_names[i].key);
|
2013-08-17 23:04:49 +00:00
|
|
|
if (value.empty())
|
|
|
|
continue;
|
2013-08-16 19:25:01 +00:00
|
|
|
|
|
|
|
std::vector<std::string> mappings;
|
|
|
|
SplitString(value, ',', mappings);
|
|
|
|
|
|
|
|
for (size_t j = 0; j < mappings.size(); j++) {
|
|
|
|
std::vector<std::string> parts;
|
|
|
|
SplitString(mappings[j], '-', parts);
|
|
|
|
int deviceId = atoi(parts[0].c_str());
|
|
|
|
int keyCode = atoi(parts[1].c_str());
|
|
|
|
|
|
|
|
SetKeyMapping(psp_button_names[i].key, KeyDef(deviceId, keyCode), false);
|
2013-07-06 18:44:34 +00:00
|
|
|
}
|
2013-08-16 19:25:01 +00:00
|
|
|
}
|
2013-08-22 10:46:35 +00:00
|
|
|
|
|
|
|
UpdateConfirmCancelKeys();
|
2013-07-06 18:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveToIni(IniFile &file) {
|
|
|
|
IniFile::Section *controls = file.GetOrCreateSection("ControlMapping");
|
2013-08-16 19:25:01 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(psp_button_names); i++) {
|
2013-08-17 08:34:38 +00:00
|
|
|
std::vector<KeyDef> keys;
|
|
|
|
KeyFromPspButton(psp_button_names[i].key, &keys);
|
2013-08-16 19:25:01 +00:00
|
|
|
|
|
|
|
std::string value;
|
2013-08-17 08:34:38 +00:00
|
|
|
for (size_t j = 0; j < keys.size(); j++) {
|
2013-08-16 19:25:01 +00:00
|
|
|
char temp[128];
|
2013-08-17 08:34:38 +00:00
|
|
|
sprintf(temp, "%i-%i", keys[j].deviceId, keys[j].keyCode);
|
2013-08-16 19:25:01 +00:00
|
|
|
value += temp;
|
2013-08-17 08:34:38 +00:00
|
|
|
if (j != keys.size() - 1)
|
2013-08-16 19:25:01 +00:00
|
|
|
value += ",";
|
2013-07-06 18:44:34 +00:00
|
|
|
}
|
2013-08-16 19:25:01 +00:00
|
|
|
|
|
|
|
controls->Set(psp_button_names[i].name.c_str(), value, "");
|
|
|
|
}
|
2013-06-14 03:30:02 +00:00
|
|
|
}
|
2013-04-20 04:52:54 +00:00
|
|
|
|
2013-07-06 17:08:59 +00:00
|
|
|
} // KeyMap
|