Added keyboard and mouse input remapping, mouse movement to joystick logic, GUI and more (#1356)

* added support for loading keyboard config from file

* final minor update before pull request

* fix messing up the merge

* fix waitEvent to correctly handle mouse inputs

* add license

* Applied coding style fixes

* clang-format fucked up the .ini file

* actually fix clang changing ini syntax
use relative path for the ini file

* remove big commented out code blocks,
and fixed platform-dependent code

* fix windows hating me

* added mouse config option

* added toggle for mouse movement input (f7)

* fix license and style

* add numpad support i accidentally left out

* added support for mouse wheel (to buttons only)

* if keyboard config doesn't exist, autogenerate it

* added keybinds for "walk mode"

* Mouse movement input is now off by default

* code cleanup and misc fixes

* delete config file since it is now autogenerated

* F6 = F7 + F9

* added better mouse handling with config options

* Added capslock support

* fix clang-format

* Added support for mod key toggle key

* F6 and F7 are removed, F9 captures and enables the mouse

* Encapsulated globals and new classes in a new namespace

* Added mouse side button support

* Added per-game config

* relocated input parser to the new namespace

* changed parser parameters to make it possible to use it from the gui

* added home, end, pgup and pgdown

* Resolved merge conflict and refactored code

* Updated default keybindings

* Changed input handling to be single-threaded

* General code cleanup

* Start working on new backend

* Mouse polling, CMakeLists, and basic framework

* Output update handling, and reworked file creating, reading and parsing

* Parsing works now

* Single key button inputs work now

* Axis outputs work now

* Wheel works now (for me), l2/r2 handling improvements, and misc bugfixes

* Downgraded prints to log_debug, and implemented input hierarchy

* Implemented key toggle

* Added mouse parameter parsing

* clang-format

* Fixed clang and added a const keyword for mac

* Fix input hierarchy

* Fixed joysick halfmodes, and possibly the last update on input hierarchy

* clang-format

* Rewrote the default config to reflect new changes

* clang

* Update code style

* Updated sorting to accomodate for that one specific edge case

* Fix default config and the latest bug with input hiearchy

* Fix typo

* Temporarily added my GUI

* Update cmakelists

* Possible fix for Gravity Rush

* Update Help text, default config, and clang

* Updated README with the new keybind info

* okay so maybe the gravity rush fix might have slightly broken the joystick halfmode and key toggle

* Fixed mistakenly overwriting the last opened config with the default one if the GUI is opened multiple times in a session

* Updated Help descriptions and fixed mouse movement default parameters

* Fix crash if the Help dialog was opened a second time
If it's closed with the top right close button instead of clicking the Help button again, a required flag wasn't reset, making the next click on Help try to close a nonexistent window and segfault

* Added closing the config also closing the Help window, and fixed more segfaults due to mismatched flags

* Initial controller support

* clang and debug print cleanup

* Initial axis-to-button logic

* Updated Help text

* Added 'Reset to Default' button in GUI

* Minor text and description updates + fixed an issue with Help text box rendering

* Fix button-to-touchpad logic and l2/r2 handling, as they are both axes and buttons
The touchpad's button state was correctly handled, so games that use that were fine, but the touchDown flag was always set to true, so games that use this flag had problems, like Gravity Rush

* Fix merge conflict

* Clang

* Added back back button to touchpad binding

* Added touchpad button handling

* Added end-of-line comments and fixed some crashes happening with the VS debugger

* Apply recent changes from kbm-only

* Deadzone + initial directional axis-to-button mapping

* Added that one missing space in the README. Are you all happy now?

* Fixups from making everything use SDL

* Revert directional joystick code and fix a memory leak

* Change config directory name again to conform to project standards

* Clang

* Revert the old deeadzone code and properly add the new one

* Clang
This commit is contained in:
kalaposfos13 2025-01-31 15:36:14 +01:00 committed by GitHub
parent f3810cebea
commit c4bfaa6031
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 1996 additions and 286 deletions

View file

@ -46,8 +46,6 @@ static std::string logType = "async";
static std::string userName = "shadPS4";
static std::string updateChannel;
static std::string chooseHomeTab;
static u16 deadZoneLeft = 2.0;
static u16 deadZoneRight = 2.0;
static std::string backButtonBehavior = "left";
static bool useSpecialPad = false;
static int specialPadClass = 1;
@ -151,14 +149,6 @@ bool getEnableDiscordRPC() {
return enableDiscordRPC;
}
u16 leftDeadZone() {
return deadZoneLeft;
}
u16 rightDeadZone() {
return deadZoneRight;
}
s16 getCursorState() {
return cursorState;
}
@ -661,8 +651,6 @@ void load(const std::filesystem::path& path) {
if (data.contains("Input")) {
const toml::value& input = data.at("Input");
deadZoneLeft = toml::find_or<float>(input, "deadZoneLeft", 2.0);
deadZoneRight = toml::find_or<float>(input, "deadZoneRight", 2.0);
cursorState = toml::find_or<int>(input, "cursorState", HideCursorState::Idle);
cursorHideTimeout = toml::find_or<int>(input, "cursorHideTimeout", 5);
backButtonBehavior = toml::find_or<std::string>(input, "backButtonBehavior", "left");
@ -785,8 +773,6 @@ void save(const std::filesystem::path& path) {
data["General"]["separateUpdateEnabled"] = separateupdatefolder;
data["General"]["compatibilityEnabled"] = compatibilityData;
data["General"]["checkCompatibilityOnStartup"] = checkCompatibilityOnStartup;
data["Input"]["deadZoneLeft"] = deadZoneLeft;
data["Input"]["deadZoneRight"] = deadZoneRight;
data["Input"]["cursorState"] = cursorState;
data["Input"]["cursorHideTimeout"] = cursorHideTimeout;
data["Input"]["backButtonBehavior"] = backButtonBehavior;
@ -919,4 +905,109 @@ void setDefaultValues() {
checkCompatibilityOnStartup = false;
}
} // namespace Config
constexpr std::string_view GetDefaultKeyboardConfig() {
return R"(#Feeling lost? Check out the Help section!
#Keyboard bindings
triangle = f
circle = space
cross = e
square = r
pad_up = w, lalt
pad_up = mousewheelup
pad_down = s, lalt
pad_down = mousewheeldown
pad_left = a, lalt
pad_left = mousewheelleft
pad_right = d, lalt
pad_right = mousewheelright
l1 = rightbutton, lshift
r1 = leftbutton
l2 = rightbutton
r2 = leftbutton, lshift
l3 = x
r3 = q
r3 = middlebutton
options = escape
touchpad = g
key_toggle = i, lalt
mouse_to_joystick = right
mouse_movement_params = 0.5, 1, 0.125
leftjoystick_halfmode = lctrl
axis_left_x_minus = a
axis_left_x_plus = d
axis_left_y_minus = w
axis_left_y_plus = s
#Controller bindings
triangle = triangle
cross = cross
square = square
circle = circle
l1 = l1
l2 = l2
l3 = l3
r1 = r1
r2 = r2
r3 = r3
pad_up = pad_up
pad_down = pad_down
pad_left = pad_left
pad_right = pad_right
options = options
touchpad = back
axis_left_x = axis_left_x
axis_left_y = axis_left_y
axis_right_x = axis_right_x
axis_right_y = axis_right_y
)";
}
std::filesystem::path GetFoolproofKbmConfigFile(const std::string& game_id) {
// Read configuration file of the game, and if it doesn't exist, generate it from default
// If that doesn't exist either, generate that from getDefaultConfig() and try again
// If even the folder is missing, we start with that.
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "input_config";
const auto config_file = config_dir / (game_id + ".ini");
const auto default_config_file = config_dir / "default.ini";
// Ensure the config directory exists
if (!std::filesystem::exists(config_dir)) {
std::filesystem::create_directories(config_dir);
}
// Check if the default config exists
if (!std::filesystem::exists(default_config_file)) {
// If the default config is also missing, create it from getDefaultConfig()
const auto default_config = GetDefaultKeyboardConfig();
std::ofstream default_config_stream(default_config_file);
if (default_config_stream) {
default_config_stream << default_config;
}
}
// if empty, we only need to execute the function up until this point
if (game_id.empty()) {
return default_config_file;
}
// If game-specific config doesn't exist, create it from the default config
if (!std::filesystem::exists(config_file)) {
std::filesystem::copy(default_config_file, config_file);
}
return config_file;
}
} // namespace Config

View file

@ -37,8 +37,6 @@ std::string getUserName();
std::string getUpdateChannel();
std::string getChooseHomeTab();
u16 leftDeadZone();
u16 rightDeadZone();
s16 getCursorState();
int getCursorHideTimeout();
std::string getBackButtonBehavior();
@ -152,6 +150,9 @@ std::string getEmulatorLanguage();
void setDefaultValues();
// todo: name and function location pending
std::filesystem::path GetFoolproofKbmConfigFile(const std::string& game_id = "");
// settings
u32 GetLanguage();
}; // namespace Config