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 65 commits into
base: main
Choose a base branch
from

Conversation

kalaposfos13
Copy link
Contributor

I changed the original hard-coded switch case keyboard inputs to handling keyboard key - controller button pairs with std::map-s, to which the input pairs get loaded to from a file in the user/ directory (currently hard-coded to keyboardInputConfig.ini).
Mouse movement is baked to the right joystick at the moment, and is handled by polling the mouse delta position.
I didn't touch the other input modes only the keyboard, to which i also put mouse input too.
The provided ini file currently has a souls inspired bloodborne layout.
I also added a robust multi-key input system that is able to accept a key-modifier key pair as input.
F8 reparses the config file and you can even change inputs while ingame
F9 toggles mouse capture

@kalaposfos13
Copy link
Contributor Author

kalaposfos13 commented Oct 13, 2024

Update:
Mouse movement input is now not hard-coded, and can be set to either joystick, and it can be toggled ingame with f7, as it currently overwrites all other inputs to the bound joystick.

@georgemoralis
Copy link
Collaborator

i have some doubt for mouse . Most games calls sceMouse lib library to do it natively . check draft #633

@kalaposfos13
Copy link
Contributor Author

Well for the games that support it just disable this? I wrote this specifically for Bloodborne that doesn't have support, and there, this works fine. I know that this isn't the cleanest option, but for some games you use either this or nothing

@georgemoralis
Copy link
Collaborator

well sure bb what else :D . Need to check how to have both working . Maybe have an config option to enable/disable this

@kalaposfos13
Copy link
Contributor Author

I checked the libMouse branch, and it looks like it can coexist with this, even without manual config other than not adding mouse bindings to my keyboardInputConfig.ini file like this:
This is my waitEvent:

case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
case SDL_EVENT_MOUSE_BUTTON_UP:
case SDL_EVENT_MOUSE_BUTTON_DOWN:
    SDL_AddTimer(33, keyRepeatCallback, (void*)payload_to_timer);
    onKeyPress(&event);
    break;

and this is yours:

case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
  onKeyPress(&event);
  break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:
case SDL_EVENT_MOUSE_BUTTON_UP:
  onMouseAction(&event);
  break;

These can be merged into one, and while I haven't tested this, this will probably work fine, since they use different things, and the overhead of checking mouse input both ways is probably negligible.
Here's an example of merging the two:

case SDL_EVENT_MOUSE_BUTTON_UP:
case SDL_EVENT_MOUSE_BUTTON_DOWN:
    onMouseAction(&event);
    // no break here
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
    SDL_AddTimer(33, keyRepeatCallback, (void*)payload_to_timer);
    onKeyPress(&event);
    break;

@stinkyolddude
Copy link

Update: Mouse movement input is now not hard-coded, and can be set to either joystick, and it can be toggled ingame with f7, as it currently overwrites all other inputs to the bound joystick.

What are the new controls and how do I change them? I really wanna take the X O Square and Triangle buttons off the Numpad. That would help a lot!

@kalaposfos13
Copy link
Contributor Author

What are the new controls and how do I change them? I really wanna take the X O Square and Triangle buttons off the Numpad. That would help a lot!

You can find the new bindings in the user/keyboardInputConfig.ini file, and they are already changed. To use it, just copy it to your user/ directory and you are good to go, and the syntax is fairly straightforward

@kalaposfos13
Copy link
Contributor Author

kalaposfos13 commented Oct 14, 2024

Quick notice, as it stands now mouse wheel support is incompatible with Logitech mouse software due to an unknown bug (the wheel inputs don't get registered correctly, the rest work fine)

@GHU7924
Copy link

GHU7924 commented Oct 20, 2024

I fully admit that my previous post might have disappointed you,
because you asked for an opinion on default.ini, but I mostly touched on CUSA03173.ini

But actually, when we talk about default.ini, it made me think deeply about
how much we should implement in it.
Of course, what ShadPS4 offers us by default now is a forced measure,
I was even overtaken by nostalgia, as if I had returned to 2007 and was about to start playing the PC port of Resident Evil 4.

What I know for sure is that we shouldn't use the control from Bloodborne in default.ini and maybe we shouldn't assign all the buttons initially.

D-Pad - Up, Left, Down, Right. (or an implementation from Bloodborne)
Left Stick - WASD
Right Stick - Mouse movement.
Option - Escape.
Should we leave the Touchpad (Back) on the G key? Maybe YES, maybe NOT.
Maybe we can even leave the X button on the E key.

But what about the rest?
Depending on the game, the other buttons change, so should we assign them at all?

Here is an example from the game Beach Buggy Racing:

BBR

L2 and R2 = movement back and forth, so when playing on the keyboard you are most likely putting:

L2 = S (or Down);
R2 = W (or Up);

But if you are playing a shooter, then L2 and R2 are already used for aiming and shooting,
so you will use the mouse:

L2 = right button;
R2 = left button;

Thus, I came to the conclusion that it might not be worth assigning all the buttons in default.ini, but you should discuss this with someone from the core development team.

defaultini.txt

These are my thoughts on what to do.

@GHU7924 GHU7924 mentioned this pull request Nov 3, 2024
using Libraries::Pad::OrbisPadButtonDataOffset;

// i wrapped it in a function so I can collapse it
std::string getDefaultKeyboardConfig() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be a separate header, and a constexpr std::string_view so it has no runtime overhead

}

// Button map: maps key+modifier to controller button
std::map<KeyBinding, u32> button_map = {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These dont belong in a windows class, please separate them in the input/ directory ideally

return state;
}

void parseInputConfig(const std::string game_id = "") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Suggested change
void parseInputConfig(const std::string game_id = "") {
void parseInputConfig(std::string_view game_id = "") {

@kalaposfos13
Copy link
Contributor Author

kalaposfos13 commented Nov 7, 2024

I'm currently rewriting this (yet again) to make inputs update flags, and then update the virtual controller from said flags to make things like wasd-to-joystick better (example: currently pressing a+d, then releasing d will stop the player even though a is still pressed), I'll incorporate these into that update.

@kalaposfos13
Copy link
Contributor Author

kalaposfos13 commented Nov 15, 2024

At this point, I think the rewrite is in a good enough state for people to start using. More 1000 lines of code translates to about 6 changes for the end user, so here they are:

  • Input combinations have changed from a key and modifier key to 3 keys of any kind.
  • modkey_toggle got renamed to key_toggle, as you can now set any key to toggle any other key's virtual state.
  • The W-S-S issue (where you press W, then S, then release S, and the character stops instead of continuing forward) is now fixed.
  • A lot of pressed input at once are now less likely to 'jam' the system
  • Wheel inputs are hopefully fixed once and for all
  • Mouse input toggle is moved from f9 to f7, as f9 is 'pause emulator' if the ctrl f10 debug menu is active

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants