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/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2013-07-06 18:44:34 +00:00
|
|
|
#include <vector>
|
2014-05-19 21:29:35 +00:00
|
|
|
#include <set>
|
2021-08-28 13:38:03 +00:00
|
|
|
|
2023-03-29 09:59:31 +00:00
|
|
|
#include "Common/Input/InputState.h" // InputMapping
|
2020-10-01 07:36:43 +00:00
|
|
|
#include "Common/Input/KeyCodes.h" // keyboard keys
|
2023-03-31 22:12:14 +00:00
|
|
|
#include "Common/Data/Collections/TinySet.h"
|
2021-08-28 13:38:03 +00:00
|
|
|
#include "Core/KeyMapDefaults.h"
|
2013-04-20 04:52:54 +00:00
|
|
|
|
|
|
|
#define KEYMAP_ERROR_KEY_ALREADY_USED -1
|
|
|
|
#define KEYMAP_ERROR_UNKNOWN_KEY 0
|
|
|
|
|
2023-03-29 11:50:57 +00:00
|
|
|
// Don't change any of these - it'll break backwards compatibility with configs.
|
2013-07-06 18:44:34 +00:00
|
|
|
enum {
|
2017-09-23 13:37:10 +00:00
|
|
|
VIRTKEY_FIRST = 0x40000001,
|
|
|
|
VIRTKEY_AXIS_X_MIN = 0x40000001,
|
|
|
|
VIRTKEY_AXIS_Y_MIN = 0x40000002,
|
|
|
|
VIRTKEY_AXIS_X_MAX = 0x40000003,
|
|
|
|
VIRTKEY_AXIS_Y_MAX = 0x40000004,
|
|
|
|
VIRTKEY_RAPID_FIRE = 0x40000005,
|
2021-08-17 14:48:47 +00:00
|
|
|
VIRTKEY_FASTFORWARD = 0x40000006,
|
2017-09-23 13:37:10 +00:00
|
|
|
VIRTKEY_PAUSE = 0x40000007,
|
|
|
|
VIRTKEY_SPEED_TOGGLE = 0x40000008,
|
|
|
|
VIRTKEY_AXIS_RIGHT_X_MIN = 0x40000009,
|
|
|
|
VIRTKEY_AXIS_RIGHT_Y_MIN = 0x4000000a,
|
|
|
|
VIRTKEY_AXIS_RIGHT_X_MAX = 0x4000000b,
|
|
|
|
VIRTKEY_AXIS_RIGHT_Y_MAX = 0x4000000c,
|
|
|
|
VIRTKEY_REWIND = 0x4000000d,
|
|
|
|
VIRTKEY_SAVE_STATE = 0x4000000e,
|
|
|
|
VIRTKEY_LOAD_STATE = 0x4000000f,
|
|
|
|
VIRTKEY_NEXT_SLOT = 0x40000010,
|
|
|
|
VIRTKEY_TOGGLE_FULLSCREEN = 0x40000011,
|
|
|
|
VIRTKEY_ANALOG_LIGHTLY = 0x40000012,
|
|
|
|
VIRTKEY_AXIS_SWAP = 0x40000013,
|
|
|
|
VIRTKEY_DEVMENU = 0x40000014,
|
|
|
|
VIRTKEY_FRAME_ADVANCE = 0x40000015,
|
2017-12-01 22:48:58 +00:00
|
|
|
VIRTKEY_RECORD = 0x40000016,
|
2018-06-17 03:07:11 +00:00
|
|
|
VIRTKEY_SPEED_CUSTOM1 = 0x40000017,
|
|
|
|
VIRTKEY_SPEED_CUSTOM2 = 0x40000018,
|
2019-03-26 05:12:02 +00:00
|
|
|
VIRTKEY_TEXTURE_DUMP = 0x40000019,
|
|
|
|
VIRTKEY_TEXTURE_REPLACE = 0x4000001A,
|
2019-05-01 02:01:20 +00:00
|
|
|
VIRTKEY_SCREENSHOT = 0x4000001B,
|
2020-02-25 11:26:23 +00:00
|
|
|
VIRTKEY_MUTE_TOGGLE = 0x4000001C,
|
2020-03-02 15:25:18 +00:00
|
|
|
VIRTKEY_OPENCHAT = 0x4000001D,
|
2020-03-23 08:24:36 +00:00
|
|
|
VIRTKEY_ANALOG_ROTATE_CW = 0x4000001E,
|
|
|
|
VIRTKEY_ANALOG_ROTATE_CCW = 0x4000001F,
|
2022-04-23 06:52:51 +00:00
|
|
|
VIRTKEY_SCREEN_ROTATION_VERTICAL = 0x40000020,
|
|
|
|
VIRTKEY_SCREEN_ROTATION_VERTICAL180 = 0x40000021,
|
|
|
|
VIRTKEY_SCREEN_ROTATION_HORIZONTAL = 0x40000022,
|
|
|
|
VIRTKEY_SCREEN_ROTATION_HORIZONTAL180 = 0x40000023,
|
2022-07-04 20:10:42 +00:00
|
|
|
VIRTKEY_SPEED_ANALOG = 0x40000024,
|
2022-10-29 18:47:29 +00:00
|
|
|
VIRTKEY_VR_CAMERA_ADJUST = 0x40000025,
|
2022-11-07 16:13:08 +00:00
|
|
|
VIRTKEY_VR_CAMERA_RESET = 0x40000026,
|
2023-05-25 11:32:49 +00:00
|
|
|
VIRTKEY_PREVIOUS_SLOT = 0x40000027,
|
2023-08-23 20:14:51 +00:00
|
|
|
VIRTKEY_TOGGLE_WLAN = 0x40000028,
|
2023-10-04 12:10:14 +00:00
|
|
|
VIRTKEY_EXIT_APP = 0x40000029,
|
2013-07-06 18:44:34 +00:00
|
|
|
VIRTKEY_LAST,
|
|
|
|
VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST
|
|
|
|
};
|
|
|
|
|
2013-07-07 22:21:40 +00:00
|
|
|
const float AXIS_BIND_THRESHOLD = 0.75f;
|
2023-04-01 15:50:17 +00:00
|
|
|
const float AXIS_BIND_RELEASE_THRESHOLD = 0.35f; // Used during mapping only to detect a "key-up" reliably.
|
2019-07-15 00:55:15 +00:00
|
|
|
const float AXIS_BIND_THRESHOLD_MOUSE = 0.01f;
|
2013-07-07 22:21:40 +00:00
|
|
|
|
2021-04-04 15:39:49 +00:00
|
|
|
struct MappedAnalogAxis {
|
|
|
|
int axisId;
|
|
|
|
int direction;
|
|
|
|
};
|
|
|
|
|
2021-04-04 15:16:26 +00:00
|
|
|
struct MappedAnalogAxes {
|
2021-04-04 15:39:49 +00:00
|
|
|
MappedAnalogAxis leftX;
|
|
|
|
MappedAnalogAxis leftY;
|
|
|
|
MappedAnalogAxis rightX;
|
|
|
|
MappedAnalogAxis rightY;
|
2021-04-04 15:16:26 +00:00
|
|
|
};
|
|
|
|
|
2013-04-20 20:33:12 +00:00
|
|
|
// KeyMap
|
2013-07-06 17:08:59 +00:00
|
|
|
// A translation layer for key assignment. Provides
|
|
|
|
// integration with Core's config state.
|
2013-12-06 14:46:56 +00:00
|
|
|
//
|
2013-07-06 17:08:59 +00:00
|
|
|
// Does not handle input state managment.
|
2013-12-06 14:46:56 +00:00
|
|
|
//
|
2013-08-04 17:31:40 +00:00
|
|
|
// Platform ports should map their platform's keys to KeyMap's keys (NKCODE_*).
|
2013-07-06 17:08:59 +00:00
|
|
|
//
|
|
|
|
// Then have KeyMap transform those into psp buttons.
|
|
|
|
|
2013-07-06 18:44:34 +00:00
|
|
|
class IniFile;
|
|
|
|
|
2013-04-20 04:52:54 +00:00
|
|
|
namespace KeyMap {
|
2023-03-31 22:12:14 +00:00
|
|
|
// Combo of InputMappings.
|
|
|
|
struct MultiInputMapping {
|
|
|
|
MultiInputMapping() {}
|
|
|
|
explicit MultiInputMapping(const InputMapping &mapping) {
|
|
|
|
mappings.push_back(mapping);
|
|
|
|
}
|
2023-04-01 11:43:42 +00:00
|
|
|
|
2023-11-13 22:43:57 +00:00
|
|
|
static MultiInputMapping FromConfigString(std::string_view str);
|
2023-04-01 11:43:42 +00:00
|
|
|
std::string ToConfigString() const;
|
2023-04-01 13:00:22 +00:00
|
|
|
std::string ToVisualString() const;
|
|
|
|
|
2023-03-31 22:12:14 +00:00
|
|
|
bool operator <(const MultiInputMapping &other) {
|
|
|
|
for (size_t i = 0; i < mappings.capacity(); i++) {
|
|
|
|
// If one ran out of entries, the other wins.
|
|
|
|
if (mappings.size() == i && other.mappings.size() > i) return true;
|
|
|
|
if (mappings.size() >= i && other.mappings.size() == i) return false;
|
|
|
|
if (mappings[i] < other.mappings[i]) return true;
|
|
|
|
if (mappings[i] > other.mappings[i]) return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator ==(const MultiInputMapping &other) const {
|
|
|
|
return mappings == other.mappings;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EqualsSingleMapping(const InputMapping &other) const {
|
|
|
|
return mappings.size() == 1 && mappings[0] == other;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool empty() const {
|
|
|
|
return mappings.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasMouse() const {
|
|
|
|
for (auto &m : mappings) {
|
|
|
|
return m.deviceId == DEVICE_ID_MOUSE;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-31 09:21:10 +00:00
|
|
|
FixedVec<InputMapping, 3> mappings;
|
2023-03-31 22:12:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::map<int, std::vector<MultiInputMapping>> KeyMapping;
|
|
|
|
|
2023-04-01 17:56:02 +00:00
|
|
|
// Once the multimappings are inserted here, they must not be empty.
|
|
|
|
// If one would be, delete the whole entry from the map instead.
|
|
|
|
// This is automatically handled by SetInputMapping.
|
2023-05-26 16:40:13 +00:00
|
|
|
extern std::set<InputDeviceID> g_seenDeviceIds;
|
2019-02-17 20:17:41 +00:00
|
|
|
extern int g_controllerMapGeneration;
|
2013-08-17 08:34:38 +00:00
|
|
|
// Key & Button names
|
|
|
|
struct KeyMap_IntStrPair {
|
|
|
|
int key;
|
2017-11-08 11:52:10 +00:00
|
|
|
const char *name;
|
2013-08-17 08:34:38 +00:00
|
|
|
};
|
|
|
|
|
2013-12-06 14:46:56 +00:00
|
|
|
// Use if you need to display the textual name
|
2023-05-26 16:40:13 +00:00
|
|
|
std::string GetKeyName(InputKeyCode keyCode);
|
2023-03-29 09:59:31 +00:00
|
|
|
std::string GetKeyOrAxisName(const InputMapping &mapping);
|
2013-08-17 09:18:45 +00:00
|
|
|
std::string GetAxisName(int axisId);
|
2013-07-06 17:08:59 +00:00
|
|
|
std::string GetPspButtonName(int btn);
|
2023-03-29 11:50:57 +00:00
|
|
|
const char *GetVirtKeyName(int vkey);
|
|
|
|
const char *GetPspButtonNameCharPointer(int btn);
|
2013-07-06 17:08:59 +00:00
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
std::vector<KeyMap_IntStrPair> GetMappableKeys();
|
|
|
|
|
2023-03-29 09:59:31 +00:00
|
|
|
// Use to translate input mappings to and from PSP buttons. You should have already translated
|
|
|
|
// your platform's keys to InputMapping keys.
|
2023-03-31 22:12:14 +00:00
|
|
|
|
|
|
|
// Note that this one does not handle combos, since there's only one input.
|
2023-03-29 09:59:31 +00:00
|
|
|
bool InputMappingToPspButton(const InputMapping &mapping, std::vector<int> *pspButtons);
|
2023-03-31 22:12:14 +00:00
|
|
|
bool InputMappingsFromPspButton(int btn, std::vector<MultiInputMapping> *keys, bool ignoreMouse);
|
2013-07-06 17:08:59 +00:00
|
|
|
|
2023-04-01 17:56:02 +00:00
|
|
|
// Simplified check.
|
|
|
|
bool PspButtonHasMappings(int btn);
|
|
|
|
|
2023-03-29 09:59:31 +00:00
|
|
|
// Configure the key or axis mapping.
|
2013-07-06 17:08:59 +00:00
|
|
|
// Any configuration will be saved to the Core config.
|
2023-03-31 22:12:14 +00:00
|
|
|
void SetInputMapping(int psp_key, const MultiInputMapping &key, bool replace);
|
2021-09-08 06:54:59 +00:00
|
|
|
// Return false if bind was a duplicate and got removed
|
2023-12-14 11:22:24 +00:00
|
|
|
bool ReplaceSingleKeyMapping(int btn, int index, const MultiInputMapping &key);
|
2013-07-06 18:44:34 +00:00
|
|
|
|
2023-05-26 16:40:13 +00:00
|
|
|
MappedAnalogAxes MappedAxesForDevice(InputDeviceID deviceId);
|
2013-07-07 22:21:40 +00:00
|
|
|
|
2013-07-06 18:44:34 +00:00
|
|
|
void LoadFromIni(IniFile &iniFile);
|
|
|
|
void SaveToIni(IniFile &iniFile);
|
2023-04-01 17:56:02 +00:00
|
|
|
void ClearAllMappings();
|
|
|
|
void DeleteNthMapping(int key, int number);
|
2013-08-16 17:34:44 +00:00
|
|
|
|
2013-08-17 08:34:38 +00:00
|
|
|
void SetDefaultKeyMap(DefaultMaps dmap, bool replace);
|
|
|
|
|
2013-07-07 09:14:46 +00:00
|
|
|
void RestoreDefault();
|
2013-04-20 04:52:54 +00:00
|
|
|
|
2015-08-28 18:55:32 +00:00
|
|
|
void UpdateNativeMenuKeys();
|
2013-09-07 09:05:27 +00:00
|
|
|
|
2023-05-26 16:40:13 +00:00
|
|
|
void NotifyPadConnected(InputDeviceID deviceId, const std::string &name);
|
2013-09-07 09:05:27 +00:00
|
|
|
bool IsNvidiaShield(const std::string &name);
|
2015-09-17 20:46:59 +00:00
|
|
|
bool IsNvidiaShieldTV(const std::string &name);
|
2013-09-07 09:05:27 +00:00
|
|
|
bool IsXperiaPlay(const std::string &name);
|
|
|
|
bool IsOuya(const std::string &name);
|
2019-09-02 22:02:57 +00:00
|
|
|
bool IsMOQII7S(const std::string &name);
|
2022-04-30 17:23:12 +00:00
|
|
|
bool IsRetroid(const std::string &name);
|
2013-09-07 09:05:27 +00:00
|
|
|
bool HasBuiltinController(const std::string &name);
|
2014-05-19 21:29:35 +00:00
|
|
|
|
|
|
|
const std::set<std::string> &GetSeenPads();
|
2023-05-26 16:40:13 +00:00
|
|
|
std::string PadName(InputDeviceID deviceId);
|
2014-05-19 21:29:35 +00:00
|
|
|
void AutoConfForPad(const std::string &name);
|
2021-08-11 21:26:39 +00:00
|
|
|
|
2023-05-26 16:40:13 +00:00
|
|
|
bool IsKeyMapped(InputDeviceID device, int key);
|
2021-08-29 15:02:52 +00:00
|
|
|
|
|
|
|
bool HasChanged(int &prevGeneration);
|
2013-10-12 07:19:02 +00:00
|
|
|
}
|