CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/KeyMap.h
Views: 1401
// Copyright (c) 2013- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#pragma once1819#include <string>20#include <map>21#include <vector>22#include <set>2324#include "Common/Input/InputState.h" // InputMapping25#include "Common/Input/KeyCodes.h" // keyboard keys26#include "Common/Data/Collections/TinySet.h"27#include "Core/KeyMapDefaults.h"2829#define KEYMAP_ERROR_KEY_ALREADY_USED -130#define KEYMAP_ERROR_UNKNOWN_KEY 03132// Don't change any of these - it'll break backwards compatibility with configs.33enum {34VIRTKEY_FIRST = 0x40000001,35VIRTKEY_AXIS_X_MIN = 0x40000001,36VIRTKEY_AXIS_Y_MIN = 0x40000002,37VIRTKEY_AXIS_X_MAX = 0x40000003,38VIRTKEY_AXIS_Y_MAX = 0x40000004,39VIRTKEY_RAPID_FIRE = 0x40000005,40VIRTKEY_FASTFORWARD = 0x40000006,41VIRTKEY_PAUSE = 0x40000007,42VIRTKEY_SPEED_TOGGLE = 0x40000008,43VIRTKEY_AXIS_RIGHT_X_MIN = 0x40000009,44VIRTKEY_AXIS_RIGHT_Y_MIN = 0x4000000a,45VIRTKEY_AXIS_RIGHT_X_MAX = 0x4000000b,46VIRTKEY_AXIS_RIGHT_Y_MAX = 0x4000000c,47VIRTKEY_REWIND = 0x4000000d,48VIRTKEY_SAVE_STATE = 0x4000000e,49VIRTKEY_LOAD_STATE = 0x4000000f,50VIRTKEY_NEXT_SLOT = 0x40000010,51VIRTKEY_TOGGLE_FULLSCREEN = 0x40000011,52VIRTKEY_ANALOG_LIGHTLY = 0x40000012,53VIRTKEY_AXIS_SWAP = 0x40000013,54VIRTKEY_DEVMENU = 0x40000014,55VIRTKEY_FRAME_ADVANCE = 0x40000015,56VIRTKEY_RECORD = 0x40000016,57VIRTKEY_SPEED_CUSTOM1 = 0x40000017,58VIRTKEY_SPEED_CUSTOM2 = 0x40000018,59VIRTKEY_TEXTURE_DUMP = 0x40000019,60VIRTKEY_TEXTURE_REPLACE = 0x4000001A,61VIRTKEY_SCREENSHOT = 0x4000001B,62VIRTKEY_MUTE_TOGGLE = 0x4000001C,63VIRTKEY_OPENCHAT = 0x4000001D,64VIRTKEY_ANALOG_ROTATE_CW = 0x4000001E,65VIRTKEY_ANALOG_ROTATE_CCW = 0x4000001F,66VIRTKEY_SCREEN_ROTATION_VERTICAL = 0x40000020,67VIRTKEY_SCREEN_ROTATION_VERTICAL180 = 0x40000021,68VIRTKEY_SCREEN_ROTATION_HORIZONTAL = 0x40000022,69VIRTKEY_SCREEN_ROTATION_HORIZONTAL180 = 0x40000023,70VIRTKEY_SPEED_ANALOG = 0x40000024,71VIRTKEY_VR_CAMERA_ADJUST = 0x40000025,72VIRTKEY_VR_CAMERA_RESET = 0x40000026,73VIRTKEY_PREVIOUS_SLOT = 0x40000027,74VIRTKEY_TOGGLE_WLAN = 0x40000028,75VIRTKEY_EXIT_APP = 0x40000029,76VIRTKEY_TOGGLE_MOUSE = 0x40000030,77VIRTKEY_TOGGLE_TOUCH_CONTROLS = 0x40000031,78VIRTKEY_RESET_EMULATION = 0x40000032,79VIRTKEY_LAST,80VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST81};8283struct MappedAnalogAxis {84int axisId;85int direction;86};8788struct MappedAnalogAxes {89MappedAnalogAxis leftX;90MappedAnalogAxis leftY;91MappedAnalogAxis rightX;92MappedAnalogAxis rightY;93};9495// KeyMap96// A translation layer for key assignment. Provides97// integration with Core's config state.98//99// Does not handle input state managment.100//101// Platform ports should map their platform's keys to KeyMap's keys (NKCODE_*).102//103// Then have KeyMap transform those into psp buttons.104105class IniFile;106107namespace KeyMap {108// Combo of InputMappings.109struct MultiInputMapping {110MultiInputMapping() {}111explicit MultiInputMapping(const InputMapping &mapping) {112mappings.push_back(mapping);113}114115static MultiInputMapping FromConfigString(std::string_view str);116std::string ToConfigString() const;117std::string ToVisualString() const;118119bool operator <(const MultiInputMapping &other) {120for (size_t i = 0; i < mappings.capacity(); i++) {121// If one ran out of entries, the other wins.122if (mappings.size() == i && other.mappings.size() > i) return true;123if (mappings.size() >= i && other.mappings.size() == i) return false;124if (mappings[i] < other.mappings[i]) return true;125if (mappings[i] > other.mappings[i]) return false;126}127return false;128}129130bool operator ==(const MultiInputMapping &other) const {131return mappings == other.mappings;132}133134bool EqualsSingleMapping(const InputMapping &other) const {135return mappings.size() == 1 && mappings[0] == other;136}137138bool empty() const {139return mappings.empty();140}141142bool HasMouse() const {143for (auto &m : mappings) {144return m.deviceId == DEVICE_ID_MOUSE;145}146return false;147}148149FixedVec<InputMapping, 3> mappings;150};151152typedef std::map<int, std::vector<MultiInputMapping>> KeyMapping;153154// Once the multimappings are inserted here, they must not be empty.155// If one would be, delete the whole entry from the map instead.156// This is automatically handled by SetInputMapping.157extern std::set<InputDeviceID> g_seenDeviceIds;158extern int g_controllerMapGeneration;159// Key & Button names160struct KeyMap_IntStrPair {161int key;162const char *name;163};164165// Use if you need to display the textual name166std::string GetKeyName(InputKeyCode keyCode);167std::string GetKeyOrAxisName(const InputMapping &mapping);168std::string GetAxisName(int axisId);169std::string GetPspButtonName(int btn);170const char *GetVirtKeyName(int vkey);171const char *GetPspButtonNameCharPointer(int btn);172173const KeyMap_IntStrPair *GetMappableKeys(size_t *count);174175// Use to translate input mappings to and from PSP buttons. You should have already translated176// your platform's keys to InputMapping keys.177178// Note that this one does not handle combos, since there's only one input.179bool InputMappingToPspButton(const InputMapping &mapping, std::vector<int> *pspButtons);180bool InputMappingsFromPspButton(int btn, std::vector<MultiInputMapping> *keys, bool ignoreMouse);181182// Careful with these.183bool InputMappingsFromPspButtonNoLock(int btn, std::vector<MultiInputMapping> *keys, bool ignoreMouse);184void LockMappings();185void UnlockMappings();186187// Simplified check.188bool PspButtonHasMappings(int btn);189190// Configure the key or axis mapping.191// Any configuration will be saved to the Core config.192void SetInputMapping(int psp_key, const MultiInputMapping &key, bool replace);193// Return false if bind was a duplicate and got removed194bool ReplaceSingleKeyMapping(int btn, int index, const MultiInputMapping &key);195196MappedAnalogAxes MappedAxesForDevice(InputDeviceID deviceId);197198void LoadFromIni(IniFile &iniFile);199void SaveToIni(IniFile &iniFile);200void ClearAllMappings();201void DeleteNthMapping(int key, int number);202203void SetDefaultKeyMap(DefaultMaps dmap, bool replace);204205void RestoreDefault();206207void UpdateNativeMenuKeys();208209void NotifyPadConnected(InputDeviceID deviceId, const std::string &name);210bool IsNvidiaShield(const std::string &name);211bool IsNvidiaShieldTV(const std::string &name);212bool IsXperiaPlay(const std::string &name);213bool IsOuya(const std::string &name);214bool IsMOQII7S(const std::string &name);215bool IsRetroid(const std::string &name);216bool HasBuiltinController(const std::string &name);217218const std::set<std::string> &GetSeenPads();219std::string PadName(InputDeviceID deviceId);220void AutoConfForPad(const std::string &name);221222bool IsKeyMapped(InputDeviceID device, int key);223224bool HasChanged(int &prevGeneration);225226// Used for setting thresholds. Technically we could allow a setting per axis, but this is a reasonable compromise.227enum class AxisType {228TRIGGER,229STICK,230OTHER,231};232233AxisType GetAxisType(InputAxis axis);234} // namespace KeyMap235236237