1
// Copyright (c) 2013- PPSSPP Project.
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
24
#include "input/input_state.h" // KeyDef, AxisPos
25
#include "input/keycodes.h" // keyboard keys
26
#include "../Core/HLE/sceCtrl.h" // psp keys
28
#define KEYMAP_ERROR_KEY_ALREADY_USED -1
29
#define KEYMAP_ERROR_UNKNOWN_KEY 0
32
VIRTKEY_FIRST = 0x10000,
33
VIRTKEY_AXIS_X_MIN = 0x10000,
34
VIRTKEY_AXIS_Y_MIN = 0x10001,
35
VIRTKEY_AXIS_X_MAX = 0x10002,
36
VIRTKEY_AXIS_Y_MAX = 0x10003,
37
VIRTKEY_RAPID_FIRE = 0x10004,
38
VIRTKEY_UNTHROTTLE = 0x10005,
39
VIRTKEY_PAUSE = 0x10006,
40
VIRTKEY_SPEED_TOGGLE = 0x10007,
41
VIRTKEY_AXIS_RIGHT_X_MIN = 0x10008,
42
VIRTKEY_AXIS_RIGHT_Y_MIN = 0x10009,
43
VIRTKEY_AXIS_RIGHT_X_MAX = 0x1000a,
44
VIRTKEY_AXIS_RIGHT_Y_MAX = 0x1000b,
45
VIRTKEY_REWIND = 0x1000c,
46
VIRTKEY_SAVE_STATE = 0x1000d,
47
VIRTKEY_LOAD_STATE = 0x1000e,
48
VIRTKEY_NEXT_SLOT = 0x1000f,
49
VIRTKEY_TOGGLE_FULLSCREEN = 0x10010,
50
VIRTKEY_ANALOG_LIGHTLY = 0x10011,
51
VIRTKEY_AXIS_SWAP = 0x10012,
52
VIRTKEY_DEVMENU = 0x10013,
54
VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST
58
DEFAULT_MAPPING_KEYBOARD,
61
DEFAULT_MAPPING_SHIELD,
62
DEFAULT_MAPPING_BLACKBERRY_QWERTY,
64
DEFAULT_MAPPING_XPERIA_PLAY,
67
const float AXIS_BIND_THRESHOLD = 0.75f;
69
typedef std::map<int, std::vector<KeyDef>> KeyMapping;
72
// A translation layer for key assignment. Provides
73
// integration with Core's config state.
75
// Does not handle input state managment.
77
// Platform ports should map their platform's keys to KeyMap's keys (NKCODE_*).
79
// Then have KeyMap transform those into psp buttons.
84
extern KeyMapping g_controllerMap;
87
struct KeyMap_IntStrPair {
92
// Use if you need to display the textual name
93
std::string GetKeyName(int keyCode);
94
std::string GetKeyOrAxisName(int keyCode);
95
std::string GetAxisName(int axisId);
96
std::string GetPspButtonName(int btn);
98
std::vector<KeyMap_IntStrPair> GetMappableKeys();
100
// Use to translate KeyMap Keys to PSP
101
// buttons. You should have already translated
102
// your platform's keys to KeyMap keys.
103
bool KeyToPspButton(int deviceId, int key, std::vector<int> *pspKeys);
104
bool KeyFromPspButton(int btn, std::vector<KeyDef> *keys);
106
int TranslateKeyCodeToAxis(int keyCode, int &direction);
107
int TranslateKeyCodeFromAxis(int axisId, int direction);
109
// Configure the key mapping.
110
// Any configuration will be saved to the Core config.
111
void SetKeyMapping(int psp_key, KeyDef key, bool replace);
113
// Configure an axis mapping, saves the configuration.
114
// Direction is negative or positive.
115
void SetAxisMapping(int btn, int deviceId, int axisId, int direction, bool replace);
117
bool AxisToPspButton(int deviceId, int axisId, int direction, std::vector<int> *pspKeys);
118
bool AxisFromPspButton(int btn, int *deviceId, int *axisId, int *direction);
119
std::string NamePspButtonFromAxis(int deviceId, int axisId, int direction);
121
void LoadFromIni(IniFile &iniFile);
122
void SaveToIni(IniFile &iniFile);
124
void SetDefaultKeyMap(DefaultMaps dmap, bool replace);
126
void RestoreDefault();
129
void UpdateNativeMenuKeys();
131
void NotifyPadConnected(const std::string &name);
132
bool IsNvidiaShield(const std::string &name);
133
bool IsNvidiaShieldTV(const std::string &name);
134
bool IsBlackberryQWERTY(const std::string &name);
135
bool IsXperiaPlay(const std::string &name);
136
bool IsOuya(const std::string &name);
137
bool HasBuiltinController(const std::string &name);
139
const std::set<std::string> &GetSeenPads();
140
void AutoConfForPad(const std::string &name);