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
|
|
|
|
2020-10-01 07:36:43 +00:00
|
|
|
#include "Common/Input/InputState.h" // KeyDef
|
|
|
|
#include "Common/Input/KeyCodes.h" // keyboard keys
|
2021-08-28 13:38:03 +00:00
|
|
|
#include "Core/HLE/sceCtrl.h" // psp keys
|
|
|
|
#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
|
|
|
|
|
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,
|
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;
|
2019-07-15 00:55:15 +00:00
|
|
|
const float AXIS_BIND_THRESHOLD_MOUSE = 0.01f;
|
2013-07-07 22:21:40 +00:00
|
|
|
|
2013-08-16 19:25:01 +00:00
|
|
|
typedef std::map<int, std::vector<KeyDef>> KeyMapping;
|
2013-08-16 17:34:44 +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 {
|
2013-08-17 08:34:38 +00:00
|
|
|
extern KeyMapping g_controllerMap;
|
2021-08-28 13:12:10 +00:00
|
|
|
extern std::set<int> 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
|
2013-07-06 17:08:59 +00:00
|
|
|
std::string GetKeyName(int keyCode);
|
2013-08-17 09:18:45 +00:00
|
|
|
std::string GetKeyOrAxisName(int keyCode);
|
|
|
|
std::string GetAxisName(int axisId);
|
2013-07-06 17:08:59 +00:00
|
|
|
std::string GetPspButtonName(int btn);
|
2021-08-30 11:13:09 +00:00
|
|
|
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();
|
|
|
|
|
2014-01-25 19:19:41 +00:00
|
|
|
// Use to translate KeyMap Keys to PSP
|
2013-07-06 17:08:59 +00:00
|
|
|
// buttons. You should have already translated
|
|
|
|
// your platform's keys to KeyMap keys.
|
2013-10-31 15:50:27 +00:00
|
|
|
bool KeyToPspButton(int deviceId, int key, std::vector<int> *pspKeys);
|
2019-07-14 06:50:01 +00:00
|
|
|
bool KeyFromPspButton(int btn, std::vector<KeyDef> *keys, bool ignoreMouse);
|
2013-07-06 17:08:59 +00:00
|
|
|
|
2013-08-17 09:18:45 +00:00
|
|
|
int TranslateKeyCodeToAxis(int keyCode, int &direction);
|
2013-08-17 08:34:38 +00:00
|
|
|
int TranslateKeyCodeFromAxis(int axisId, int direction);
|
2013-07-06 17:08:59 +00:00
|
|
|
|
|
|
|
// Configure the key mapping.
|
|
|
|
// Any configuration will be saved to the Core config.
|
2013-08-16 19:25:01 +00:00
|
|
|
void SetKeyMapping(int psp_key, KeyDef key, bool replace);
|
2021-09-08 06:54:59 +00:00
|
|
|
// Return false if bind was a duplicate and got removed
|
|
|
|
bool ReplaceSingleKeyMapping(int btn, int index, KeyDef key);
|
2013-08-16 19:25:01 +00:00
|
|
|
|
|
|
|
// Configure an axis mapping, saves the configuration.
|
|
|
|
// Direction is negative or positive.
|
2013-08-17 08:34:38 +00:00
|
|
|
void SetAxisMapping(int btn, int deviceId, int axisId, int direction, bool replace);
|
2013-07-06 18:44:34 +00:00
|
|
|
|
2013-10-31 15:50:27 +00:00
|
|
|
bool AxisToPspButton(int deviceId, int axisId, int direction, std::vector<int> *pspKeys);
|
2013-08-16 17:34:44 +00:00
|
|
|
bool AxisFromPspButton(int btn, int *deviceId, int *axisId, int *direction);
|
2021-04-04 15:16:26 +00:00
|
|
|
MappedAnalogAxes MappedAxesForDevice(int 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);
|
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
|
|
|
|
2014-11-07 12:40:53 +00:00
|
|
|
void SwapAxis();
|
2015-08-28 18:55:32 +00:00
|
|
|
void UpdateNativeMenuKeys();
|
2013-09-07 09:05:27 +00:00
|
|
|
|
2022-07-04 19:49:38 +00:00
|
|
|
void NotifyPadConnected(int 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();
|
2022-07-04 20:10:42 +00:00
|
|
|
std::string PadName(int deviceId);
|
2014-05-19 21:29:35 +00:00
|
|
|
void AutoConfForPad(const std::string &name);
|
2021-08-11 21:26:39 +00:00
|
|
|
|
|
|
|
bool IsKeyMapped(int device, int key);
|
2021-08-29 15:02:52 +00:00
|
|
|
|
|
|
|
bool HasChanged(int &prevGeneration);
|
2013-10-12 07:19:02 +00:00
|
|
|
}
|