Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added keyboard and mouse input remapping, rudimentary mouse movement to joystick logic and more #1356

Open
wants to merge 74 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
81e0f14
added support for loading keyboard config from file
kalaposfos13 Oct 12, 2024
94c0764
final minor update before pull request
kalaposfos13 Oct 12, 2024
37dcdce
fix messing up the merge
kalaposfos13 Oct 12, 2024
f6d54bf
fix waitEvent to correctly handle mouse inputs
kalaposfos13 Oct 12, 2024
3dda62f
add license
kalaposfos13 Oct 12, 2024
9820022
Applied coding style fixes
kalaposfos13 Oct 12, 2024
22e4ab8
clang-format fucked up the .ini file
kalaposfos13 Oct 12, 2024
31caf01
Merge branch 'shadps4-emu:main' into main
kalaposfos13 Oct 12, 2024
45f05c0
actually fix clang changing ini syntax
kalaposfos13 Oct 12, 2024
b15810d
remove big commented out code blocks,
kalaposfos13 Oct 13, 2024
719a36c
fix windows hating me
kalaposfos13 Oct 13, 2024
607514e
added mouse config option
kalaposfos13 Oct 13, 2024
6a2eab3
added toggle for mouse movement input (f7)
kalaposfos13 Oct 13, 2024
b300ffe
fix license and style
kalaposfos13 Oct 13, 2024
ef7b0ad
add numpad support i accidentally left out
kalaposfos13 Oct 13, 2024
17e44de
added support for mouse wheel (to buttons only)
kalaposfos13 Oct 14, 2024
1ec9dc0
if keyboard config doesn't exist, autogenerate it
kalaposfos13 Oct 14, 2024
f486663
added keybinds for "walk mode"
kalaposfos13 Oct 14, 2024
bd2acfa
Mouse movement input is now off by default
kalaposfos13 Oct 15, 2024
c5391ba
Merge branch 'shadps4-emu:main' into main
kalaposfos13 Oct 15, 2024
4c6bee8
code cleanup and misc fixes
kalaposfos13 Oct 15, 2024
60d9e7b
delete config file since it is now autogenerated
kalaposfos13 Oct 15, 2024
a76b792
F6 = F7 + F9
kalaposfos13 Oct 15, 2024
649a5c0
Merge branch 'shadps4-emu:main' into main
kalaposfos13 Oct 15, 2024
92bbe40
added better mouse handling with config options
kalaposfos13 Oct 16, 2024
1788aed
Added capslock support
kalaposfos13 Oct 16, 2024
b00ebf3
fix clang-format
kalaposfos13 Oct 17, 2024
5fdaea8
Added support for mod key toggle key
kalaposfos13 Oct 17, 2024
52b06c4
F6 and F7 are removed, F9 captures and enables the mouse
kalaposfos13 Oct 17, 2024
d0238e1
Merge remote-tracking branch 'upstream/main'
kalaposfos13 Oct 18, 2024
24348f6
Encapsulated globals and new classes in a new namespace
kalaposfos13 Oct 18, 2024
2c913a1
Added mouse side button support
kalaposfos13 Oct 18, 2024
2c51aee
Merge remote-tracking branch 'upstream/main'
kalaposfos13 Oct 18, 2024
e0b288a
Added per-game config
kalaposfos13 Oct 18, 2024
942c1d8
relocated input parser to the new namespace
kalaposfos13 Oct 18, 2024
52ad7e0
changed parser parameters to make it possible to use it from the gui
kalaposfos13 Oct 18, 2024
050ba2e
added home, end, pgup and pgdown
kalaposfos13 Oct 18, 2024
abbff1f
Merge branch 'upstreamMain'
kalaposfos13 Oct 20, 2024
f7b8f5e
Resolved merge conflict and refactored code
kalaposfos13 Oct 20, 2024
7ab5085
Updated default keybindings
kalaposfos13 Oct 20, 2024
e3408a2
Merge remote-tracking branch 'upstream/main' - update to 0.4.0
kalaposfos13 Oct 31, 2024
cd4d3c5
Changed input handling to be single-threaded
kalaposfos13 Oct 31, 2024
9958033
General code cleanup
kalaposfos13 Oct 31, 2024
204f906
Merge remote-tracking branch 'upstream/main'
kalaposfos13 Nov 2, 2024
a657e22
Merge remote-tracking branch 'upstream/main'
kalaposfos13 Nov 7, 2024
7a95c27
Start working on new backend
kalaposfos13 Nov 12, 2024
1884b39
Mouse polling, CMakeLists, and basic framework
kalaposfos13 Nov 13, 2024
d92a83c
Output update handling, and reworked file creating, reading and parsing
kalaposfos13 Nov 13, 2024
86c8701
Parsing works now
kalaposfos13 Nov 13, 2024
5c2d09d
Single key button inputs work now
kalaposfos13 Nov 13, 2024
df738c6
Axis outputs work now
kalaposfos13 Nov 13, 2024
0d87d0d
Wheel works now (for me), l2/r2 handling improvements, and misc bugfixes
kalaposfos13 Nov 14, 2024
6ad6079
Downgraded prints to log_debug, and implemented input hierarchy
kalaposfos13 Nov 14, 2024
09b945c
Implemented key toggle
kalaposfos13 Nov 14, 2024
1a8f177
Added mouse parameter parsing
kalaposfos13 Nov 14, 2024
9c81f8e
clang-format
kalaposfos13 Nov 14, 2024
e215530
Merge remote-tracking branch 'upstream/main'
kalaposfos13 Nov 14, 2024
e38e75b
Merge branch 'new-kbm'
kalaposfos13 Nov 14, 2024
3e512bc
Fixed clang and added a const keyword for mac
kalaposfos13 Nov 14, 2024
1efd247
Fix input hierarchy
kalaposfos13 Nov 14, 2024
e43d60e
Fixed joysick halfmodes, and possibly the last update on input hierarchy
kalaposfos13 Nov 15, 2024
900b578
clang-format
kalaposfos13 Nov 15, 2024
94c6a9f
Rewrote the default config to reflect new changes
kalaposfos13 Nov 15, 2024
9d6dd79
clang
kalaposfos13 Nov 15, 2024
91e30ac
Update code style
kalaposfos13 Nov 15, 2024
f5f988d
Updated sorting to accomodate for that one specific edge case
kalaposfos13 Nov 15, 2024
3d4db91
Fix default config and the latest bug with input hiearchy
kalaposfos13 Nov 15, 2024
0110009
Fix typo
kalaposfos13 Nov 16, 2024
9062be0
Temporarily added my GUI
kalaposfos13 Nov 16, 2024
5b6da2b
Update cmakelists
kalaposfos13 Nov 16, 2024
3466de0
Possible fix for Gravity Rush
kalaposfos13 Nov 16, 2024
3261674
Update Help text, default config, and clang
kalaposfos13 Nov 16, 2024
0a1b875
Updated README with the new keybind info
kalaposfos13 Nov 16, 2024
45cc82e
okay so maybe the gravity rush fix might have slightly broken the joy…
kalaposfos13 Nov 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ set(IMGUI src/imgui/imgui_config.h

set(INPUT src/input/controller.cpp
src/input/controller.h
src/input/input_handler.cpp
src/input/input_handler.h
)

set(EMULATOR src/emulator.cpp
Expand Down Expand Up @@ -771,6 +773,10 @@ set(QT_GUI src/qt_gui/about_dialog.cpp
src/qt_gui/trophy_viewer.h
src/qt_gui/elf_viewer.cpp
src/qt_gui/elf_viewer.h
src/qt_gui/kbm_config_dialog.cpp
src/qt_gui/kbm_config_dialog.h
src/qt_gui/kbm_help_dialog.cpp
src/qt_gui/kbm_help_dialog.h
src/qt_gui/main_window_themes.cpp
src/qt_gui/main_window_themes.h
src/qt_gui/settings_dialog.cpp
Expand Down
56 changes: 29 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,39 @@ Check the build instructions for [**macOS**](https://github.com/shadps4-emu/shad

For more information on how to test, debug and report issues with the emulator or games, read the [**Debugging documentation**](https://github.com/shadps4-emu/shadPS4/blob/main/documents/Debugging/Debugging.md).

# Keyboard mapping
# Keyboard and Mouse Mappings

> [!NOTE]
> Xbox and DualShock controllers work out of the box.

| Controller button | Keyboard equivelant |
|-------------|-------------|
LEFT AXIS UP | W |
LEFT AXIS DOWN | S |
LEFT AXIS LEFT | A |
LEFT AXIS RIGHT | D |
RIGHT AXIS UP | I |
RIGHT AXIS DOWN | K |
RIGHT AXIS LEFT | J |
RIGHT AXIS RIGHT | L |
TRIANGLE | Numpad 8 |
CIRCLE | Numpad 6 |
CROSS | Numpad 2 |
SQUARE | Numpad 4 |
PAD UP | UP |
PAD DOWN | DOWN |
PAD LEFT | LEFT |
PAD RIGHT | RIGHT |
OPTIONS | RETURN |
BACK BUTTON / TOUCH PAD | SPACE |
L1 | Q |
R1 | U |
L2 | E |
R2 | O |
L3 | X |
R3 | M |
The default controls are inspired by the *Elden Ring* PC controls. Inputs support up to three keys per binding, mouse buttons, mouse movement mapped to joystick input, and more.

| Action | Default Key(s) |
|-------------|-----------------------------|
| Triangle | F |
| Circle | Space |
| Cross | E |
| Square | R |
| Pad Up | W, LAlt / Mouse Wheel Up |
| Pad Down | S, LAlt / Mouse Wheel Down |
| Pad Left | A, LAlt / Mouse Wheel Left |
| Pad Right | D, LAlt / Mouse Wheel Right |
| L1 | Right Button, LShift |
| R1 | Left Button |
| L2 | Right Button |
| R2 | Left Button, LShift |
| L3 | X |
| R3 | Q / Middle Button |
| Options | Escape |
| Touchpad | G |

| Joystick | Default Input |
|--------------------|----------------|
| Left Joystick | WASD |
| Right Joystick | Mouse movement |

Keyboard and mouse inputs can be customized in the settings menu by clicking the Controller button, and further details and help on controls are also found there. Custom bindings are saved per-game.


# Main team

Expand Down
78 changes: 78 additions & 0 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,82 @@ void setDefaultValues() {
gpuId = -1;
}

constexpr std::string_view GetDefaultKeyboardConfig() {
return R"(#Feeling lost? Check out the Help section!

triangle = f
circle = space
cross = e
square = r

up = w, lalt
up = mousewheelup
down = s, lalt
down = mousewheeldown
left = a, lalt
left = mousewheelleft
right = d, lalt
right = mousewheelright

l1 = rightbutton, lshift
r1 = leftbutton
l2 = rightbutton
r2 = leftbutton, lshift
l3 = x
r3 = q
r3 = middlebutton

key_toggle = i, lalt

options = escape
touchpad = g


mouse_to_joystick = right
mouse_movement_params = 1, 0.5, 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
)";
}
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) / "kbmConfig";
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
3 changes: 3 additions & 0 deletions src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,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
Loading