diff --git a/core/libs/prx/libSceVideoOut/src/InputMapping.cpp b/core/libs/prx/libSceVideoOut/src/InputMapping.cpp index 33df257b3..d3d3d7275 100644 --- a/core/libs/prx/libSceVideoOut/src/InputMapping.cpp +++ b/core/libs/prx/libSceVideoOut/src/InputMapping.cpp @@ -6,12 +6,14 @@ #include #include #include +#include #include #include #include #include #include "SDL_keyboard.h" +#include "SDL_filesystem.h" namespace { @@ -123,13 +125,19 @@ Pad::InputBinding parseBinding(const InputAction& action, std::string_view sourc throw std::runtime_error("Pad: invalid input mapping " + path.string() + ":" + std::to_string(line) + ": " + reason); } +std::filesystem::path defaultConfigPath() { + std::unique_ptr basePath(SDL_GetBasePath(), SDL_free); + if (basePath) return std::filesystem::path(basePath.get()) / "anyps5-input.ini"; + return "anyps5-input.ini"; +} + } std::vector Pad::LoadInputMapping() { std::vector bindings(InputMapping.begin(), InputMapping.end()); const char* configuredPath = std::getenv("ANYPS5_INPUT_CONFIG"); const bool explicitPath = configuredPath != nullptr && configuredPath[0] != '\0'; - const std::filesystem::path path = explicitPath ? configuredPath : "anyps5-input.ini"; + const std::filesystem::path path = explicitPath ? configuredPath : defaultConfigPath(); std::ifstream file(path); if (!file) { if (explicitPath || std::filesystem::exists(path)) { diff --git a/docs/INPUT_MAPPING.md b/docs/INPUT_MAPPING.md index e79ffd25a..da678ffbd 100644 --- a/docs/INPUT_MAPPING.md +++ b/docs/INPUT_MAPPING.md @@ -1,6 +1,6 @@ # Keyboard and mouse mapping -AnyPS5 uses its built-in keyboard and mouse bindings when no configuration file is present. To change selected bindings, create `anyps5-input.ini` in the game's working directory. Set `ANYPS5_INPUT_CONFIG` to use a file at another path. +AnyPS5 uses its built-in keyboard and mouse bindings when no configuration file is present. To change selected bindings, create `anyps5-input.ini` beside the generated game executable. Set `ANYPS5_INPUT_CONFIG` to use a file at another path. Each non-empty line has the form `Action = Type:Value`. Action names are case-insensitive. A `#` or `;` starts a comment. The first line for an action replaces its built-in bindings; later lines for the same action add alternate inputs. Duplicate entries for the same action are ignored. Actions omitted from the file keep their built-in bindings. UTF-8 files with or without a byte-order mark are supported.