2013-04-19 22:52:54 -06: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 20:44:34 +02:00
|
|
|
#include <vector>
|
2014-05-19 23:29:35 +02:00
|
|
|
#include <set>
|
2021-08-28 15:38:03 +02:00
|
|
|
|
2020-10-01 09:36:43 +02:00
|
|
|
#include "Common/Input/InputState.h" // KeyDef
|
|
|
|
#include "Common/Input/KeyCodes.h" // keyboard keys
|
2021-08-28 15:38:03 +02:00
|
|
|
#include "Core/HLE/sceCtrl.h" // psp keys
|
|
|
|
#include "Core/KeyMapDefaults.h"
|
2013-04-19 22:52:54 -06:00
|
|
|
|
|
|
|
#define KEYMAP_ERROR_KEY_ALREADY_USED -1
|
|
|
|
#define KEYMAP_ERROR_UNKNOWN_KEY 0
|
|
|
|
|
2013-07-06 20:44:34 +02:00
|
|
|
enum {
|
2017-09-23 15:37:10 +02: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 16:48:47 +02:00
|
|
|
VIRTKEY_FASTFORWARD = 0x40000006,
|
2017-09-23 15:37:10 +02: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 23:48:58 +01:00
|
|
|
VIRTKEY_RECORD = 0x40000016,
|
2018-06-16 20:07:11 -07:00
|
|
|
VIRTKEY_SPEED_CUSTOM1 = 0x40000017,
|
|
|
|
VIRTKEY_SPEED_CUSTOM2 = 0x40000018,
|
2019-03-26 06:12:02 +01:00
|
|
|
VIRTKEY_TEXTURE_DUMP = 0x40000019,
|
|
|
|
VIRTKEY_TEXTURE_REPLACE = 0x4000001A,
|
2019-04-30 19:01:20 -07:00
|
|
|
VIRTKEY_SCREENSHOT = 0x4000001B,
|
2020-02-25 12:26:23 +01:00
|
|
|
VIRTKEY_MUTE_TOGGLE = 0x4000001C,
|
2020-03-02 22:25:18 +07:00
|
|
|
VIRTKEY_OPENCHAT = 0x4000001D,
|
2020-03-23 09:24:36 +01:00
|
|
|
VIRTKEY_ANALOG_ROTATE_CW = 0x4000001E,
|
|
|
|
VIRTKEY_ANALOG_ROTATE_CCW = 0x4000001F,
|
2022-04-23 08:52:51 +02:00
|
|
|
VIRTKEY_SCREEN_ROTATION_VERTICAL = 0x40000020,
|
|
|
|
VIRTKEY_SCREEN_ROTATION_VERTICAL180 = 0x40000021,
|
|
|
|
VIRTKEY_SCREEN_ROTATION_HORIZONTAL = 0x40000022,
|
|
|
|
VIRTKEY_SCREEN_ROTATION_HORIZONTAL180 = 0x40000023,
|
2022-07-04 13:10:42 -07:00
|
|
|
VIRTKEY_SPEED_ANALOG = 0x40000024,
|
2013-07-06 20:44:34 +02:00
|
|
|
VIRTKEY_LAST,
|
|
|
|
VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST
|
|
|
|
};
|
|
|
|
|
2013-07-07 15:21:40 -07:00
|
|
|
const float AXIS_BIND_THRESHOLD = 0.75f;
|
2019-07-15 02:55:15 +02:00
|
|
|
const float AXIS_BIND_THRESHOLD_MOUSE = 0.01f;
|
2013-07-07 15:21:40 -07:00
|
|
|
|
2013-08-16 21:25:01 +02:00
|
|
|
typedef std::map<int, std::vector<KeyDef>> KeyMapping;
|
2013-08-16 19:34:44 +02:00
|
|
|
|
2021-04-04 08:39:49 -07:00
|
|
|
struct MappedAnalogAxis {
|
|
|
|
int axisId;
|
|
|
|
int direction;
|
|
|
|
};
|
|
|
|
|
2021-04-04 08:16:26 -07:00
|
|
|
struct MappedAnalogAxes {
|
2021-04-04 08:39:49 -07:00
|
|
|
MappedAnalogAxis leftX;
|
|
|
|
MappedAnalogAxis leftY;
|
|
|
|
MappedAnalogAxis rightX;
|
|
|
|
MappedAnalogAxis rightY;
|
2021-04-04 08:16:26 -07:00
|
|
|
};
|
|
|
|
|
2013-04-20 14:33:12 -06:00
|
|
|
// KeyMap
|
2013-07-06 19:08:59 +02:00
|
|
|
// A translation layer for key assignment. Provides
|
|
|
|
// integration with Core's config state.
|
2013-12-06 15:46:56 +01:00
|
|
|
//
|
2013-07-06 19:08:59 +02:00
|
|
|
// Does not handle input state managment.
|
2013-12-06 15:46:56 +01:00
|
|
|
//
|
2013-08-05 03:31:40 +10:00
|
|
|
// Platform ports should map their platform's keys to KeyMap's keys (NKCODE_*).
|
2013-07-06 19:08:59 +02:00
|
|
|
//
|
|
|
|
// Then have KeyMap transform those into psp buttons.
|
|
|
|
|
2013-07-06 20:44:34 +02:00
|
|
|
class IniFile;
|
|
|
|
|
2013-04-19 22:52:54 -06:00
|
|
|
namespace KeyMap {
|
2013-08-17 10:34:38 +02:00
|
|
|
extern KeyMapping g_controllerMap;
|
2021-08-28 15:12:10 +02:00
|
|
|
extern std::set<int> g_seenDeviceIds;
|
2019-02-17 12:17:41 -08:00
|
|
|
extern int g_controllerMapGeneration;
|
2013-08-17 10:34:38 +02:00
|
|
|
|
|
|
|
// Key & Button names
|
|
|
|
struct KeyMap_IntStrPair {
|
|
|
|
int key;
|
2017-11-08 12:52:10 +01:00
|
|
|
const char *name;
|
2013-08-17 10:34:38 +02:00
|
|
|
};
|
|
|
|
|
2013-12-06 15:46:56 +01:00
|
|
|
// Use if you need to display the textual name
|
2013-07-06 19:08:59 +02:00
|
|
|
std::string GetKeyName(int keyCode);
|
2013-08-17 11:18:45 +02:00
|
|
|
std::string GetKeyOrAxisName(int keyCode);
|
|
|
|
std::string GetAxisName(int axisId);
|
2013-07-06 19:08:59 +02:00
|
|
|
std::string GetPspButtonName(int btn);
|
2021-08-30 13:13:09 +02:00
|
|
|
const char* GetPspButtonNameCharPointer(int btn);
|
2013-07-06 19:08:59 +02:00
|
|
|
|
2013-08-17 10:34:38 +02:00
|
|
|
std::vector<KeyMap_IntStrPair> GetMappableKeys();
|
|
|
|
|
2014-01-25 11:19:41 -08:00
|
|
|
// Use to translate KeyMap Keys to PSP
|
2013-07-06 19:08:59 +02:00
|
|
|
// buttons. You should have already translated
|
|
|
|
// your platform's keys to KeyMap keys.
|
2013-10-31 16:50:27 +01:00
|
|
|
bool KeyToPspButton(int deviceId, int key, std::vector<int> *pspKeys);
|
2019-07-14 08:50:01 +02:00
|
|
|
bool KeyFromPspButton(int btn, std::vector<KeyDef> *keys, bool ignoreMouse);
|
2013-07-06 19:08:59 +02:00
|
|
|
|
2013-08-17 11:18:45 +02:00
|
|
|
int TranslateKeyCodeToAxis(int keyCode, int &direction);
|
2013-08-17 10:34:38 +02:00
|
|
|
int TranslateKeyCodeFromAxis(int axisId, int direction);
|
2013-07-06 19:08:59 +02:00
|
|
|
|
|
|
|
// Configure the key mapping.
|
|
|
|
// Any configuration will be saved to the Core config.
|
2013-08-16 21:25:01 +02:00
|
|
|
void SetKeyMapping(int psp_key, KeyDef key, bool replace);
|
2021-09-08 08:54:59 +02:00
|
|
|
// Return false if bind was a duplicate and got removed
|
|
|
|
bool ReplaceSingleKeyMapping(int btn, int index, KeyDef key);
|
2013-08-16 21:25:01 +02:00
|
|
|
|
|
|
|
// Configure an axis mapping, saves the configuration.
|
|
|
|
// Direction is negative or positive.
|
2013-08-17 10:34:38 +02:00
|
|
|
void SetAxisMapping(int btn, int deviceId, int axisId, int direction, bool replace);
|
2013-07-06 20:44:34 +02:00
|
|
|
|
2013-10-31 16:50:27 +01:00
|
|
|
bool AxisToPspButton(int deviceId, int axisId, int direction, std::vector<int> *pspKeys);
|
2013-08-16 19:34:44 +02:00
|
|
|
bool AxisFromPspButton(int btn, int *deviceId, int *axisId, int *direction);
|
2021-04-04 08:16:26 -07:00
|
|
|
MappedAnalogAxes MappedAxesForDevice(int deviceId);
|
2013-07-07 15:21:40 -07:00
|
|
|
|
2013-07-06 20:44:34 +02:00
|
|
|
void LoadFromIni(IniFile &iniFile);
|
|
|
|
void SaveToIni(IniFile &iniFile);
|
2013-08-16 19:34:44 +02:00
|
|
|
|
2013-08-17 10:34:38 +02:00
|
|
|
void SetDefaultKeyMap(DefaultMaps dmap, bool replace);
|
|
|
|
|
2013-07-07 11:14:46 +02:00
|
|
|
void RestoreDefault();
|
2013-04-19 22:52:54 -06:00
|
|
|
|
2014-11-07 22:40:53 +10:00
|
|
|
void SwapAxis();
|
2015-08-28 20:55:32 +02:00
|
|
|
void UpdateNativeMenuKeys();
|
2013-09-07 11:05:27 +02:00
|
|
|
|
2022-07-04 12:49:38 -07:00
|
|
|
void NotifyPadConnected(int deviceId, const std::string &name);
|
2013-09-07 11:05:27 +02:00
|
|
|
bool IsNvidiaShield(const std::string &name);
|
2015-09-17 22:46:59 +02:00
|
|
|
bool IsNvidiaShieldTV(const std::string &name);
|
2013-09-07 11:05:27 +02:00
|
|
|
bool IsXperiaPlay(const std::string &name);
|
|
|
|
bool IsOuya(const std::string &name);
|
2019-09-03 00:02:57 +02:00
|
|
|
bool IsMOQII7S(const std::string &name);
|
2022-04-30 19:23:12 +02:00
|
|
|
bool IsRetroid(const std::string &name);
|
2013-09-07 11:05:27 +02:00
|
|
|
bool HasBuiltinController(const std::string &name);
|
2014-05-19 23:29:35 +02:00
|
|
|
|
|
|
|
const std::set<std::string> &GetSeenPads();
|
2022-07-04 13:10:42 -07:00
|
|
|
std::string PadName(int deviceId);
|
2014-05-19 23:29:35 +02:00
|
|
|
void AutoConfForPad(const std::string &name);
|
2021-08-11 23:26:39 +02:00
|
|
|
|
|
|
|
bool IsKeyMapped(int device, int key);
|
2021-08-29 08:02:52 -07:00
|
|
|
|
|
|
|
bool HasChanged(int &prevGeneration);
|
2013-10-12 17:19:02 +10:00
|
|
|
}
|