komefai / PS4Macro

Automation utility for PS4 Remote Play written in C#
http://blog.komefai.com
MIT License
376 stars 89 forks source link

[Feature Testing] Mouse input in Remapper #13

Open komefai opened 6 years ago

komefai commented 6 years ago

This issue is for anyone who want to try the "Mouse input" feature in Remapper. The feature not yet ready, and that is why I decided to delay the release of the next version and release this debug build here instead. You can help me improve this feature by testing it with different games and report the bugs in this issue.

Usage

Open Remapper and check "Enable Mouse", then click on PS4 Remote Play to focus the window. To stop, you can press Alt+Tab to focus other windows.

Mouse Input Settings

NOTE: Default settings are recommended (except for Sensitivity) but feel free to play around with it for different games.

Sensitivity - The amount used to multiply the speed of the mouse Decay Rate - The amount used to divide the speed of the mouse every frame after the mouse stopped moving Decay Threshold - Threshold of the speed (will decay until the speed drops below the threshold) Deadzone - The offset amount from analog stick center to start from (use 0 to start from the center) [Value ranges from 0-127] Makeup Speed - The amount used to multiply AFTER the mouse speed is scaled into analog values to compensate the lost from the decay

Example Deadzone=14.25 (green box represents the deadzone)

Analog stick movement will start at the green line instead of starting from the exact center. remapper_mouse_deadzone


View source: https://github.com/komefai/PS4Macro/blob/master/PS4Macro/Classes/Remapping/Remapper.cs

Screenshot

Screenshot

Download

LATEST (14/04/2018)

-> Multi-monitor support -> Middle click bindings

PS4Macro_cf7ce2c.zip -[commit cf7ce2c]

Previous Builds (oldest first)
  1. PS4Macro_1408820.zip - [commit 1408820]
  2. PS4Macro_2d3d6e2.zip - [commit 2d3d6e2]
  3. PS4Macro_2ec5033.zip - [commit 2ec5033] (Special thanks to Y-T-G)
  4. PS4Macro_c43dbd4.zip - [commit c43dbd4]
  5. PS4Macro_658584b.zip - [commit 658584b] (Special thanks to Y-T-G again!)
Y-T-G commented 6 years ago

I would like to try. Will see what I can report.

Y-T-G commented 6 years ago

@komefai The sensitivity is so high even at lowest setting. Do I have to tweak the in-game sensitivity? I would also like different sensitivity settings for Aim Down Sight UPDATE- There seems to be a bug: Moving the mouse faster moves the screen slower and moving it slower moves (quickly jerks) the screen faster. I guess the sensitivity issue I am experiencing is due to this.

komefai commented 6 years ago

@Y-T-G Thanks for the report! I agree about the sensitivity, probably have to scale it down after calculating the speed. Next build coming soon.

EDIT: Updated [commit 2d3d6e2]

Y-T-G commented 6 years ago

@komefai Did you observe anything like the next issue I was having? Slow mouse movements are fast and fast movements are slow. Might be that only the latter is true, and the former is just because the latter is relatively slow, not sure. UPDATE: After some testing, it seems that remapper has not been programmed to consider in game deadzone. For example in RB6, keeping in game deadzone minimum, there is "Right" movement only when scaledX >=160(maybe slightly more or slightly less) rx>= 142.65(that's as precise I could get; movement was extremely minuscle even at 100 sensitivity in game) . So, smaller movements get ignored unless you tweak the sensitivity which does not solve it entirely either.

Y-T-G commented 6 years ago

@komefai Using

double rx = ((MouseSpeedX > 0) ? 142.65 : ((MouseSpeedX < 0) ? 113.25 : 128)) + (MouseSpeedX * 127);
double ry = ((MouseSpeedY > 0) ? 142.65 : ((MouseSpeedY < 0) ? 113.25 : 128)) + (MouseSpeedY * 127);

has smoothened things up a lot.

Y-T-G commented 6 years ago

Is MouseRecenter interfering with movements? Small movements are occasionally being countered by reverse movements. EDIT: Setting Deadzone 0 solves this.

komefai commented 6 years ago

@Y-T-G Hi, thanks for the info, it should save me a lot of time! Sorry for the slow response I've been quite busy with other personal projects lately. I'll try your suggested modifications as soon as I get the chance.

Is MouseRecenter interfering with movements? Small movements are occasionally being countered by reverse movements.

That is very possible actually, I think I might remove the mouse centering entirely because I already implemented mouse overflow which makes recentering unnecessary.

Y-T-G commented 6 years ago

@komefai

Sorry for the slow response I've been quite busy with other personal projects lately

No problem. Can you tell me what is the purpose of this ?: MouseSpeedX * 127 & MouseSpeedY * 127

komefai commented 6 years ago

@Y-T-G

double rx = 128 + (MouseSpeedX * 127);
double ry = 128 + (MouseSpeedY * 127);

The formula is part of normalizing the values back into the joystick scale. When you substitute 0, 1 and so on, into MouseSpeed this will give:

128 + (-1 * 127) = 1
128 + (0 * 127) = 128
128 + (1 * 127) = 255

Which is the minimum of the analog, the center of the analog (idle), and the maximum of the analog.

The part after that clamps the values between 0 and 255, keeping it in range:

byte scaledX = (byte)((rx < min) ? min : (rx > max) ? max : rx);
byte scaledY = (byte)((ry < min) ? min : (ry > max) ? max : ry);
SD777x commented 6 years ago

Just wanted to say thank you so much for taking the time to do something this awesome!! If and when you decide to charge for this I have no issue paying for a finished version. I had a few requests I hope you would have time to consider.

1) Can we remap buttons to keys such as arrow keys on the keyboard? I tried but it seems Remapper only takes letters. Years of using arrow keys instead of WASD. I suppose same question for other keys which I use a lot such as Delete, Page up/down, and number keys on the keyboard number pad, etc.

2) Can we stretch the Remapper window to be larger? I have a 2nd screen that I put the Remapper screen on so I can remember all the remaps, but I can only see about 1/3 of them. I'd love to stretch the window longer so I can see all the remaps/commands.

In terms of this build, I've been testing out the mouse function in Horizon Zero Dawn and find many of the things YTG has found. There seems to be some kind of bounce back, so if I move the mouse to the right the view bounces back to the left. It's also interesting to watch the right stick key in the remapper screen which shows the emulated stick seems to only be emulating the 4 diagonal corners and not purely up/down. I read through your comments about deadzone and mouse recenter and I hope these fixes make it into the next version. I'm glad to help debug or troubleshoot in any way.

Finally, WTF is this not more popular?!?! I am a long time PC player and only got a PS4 a week ago and already HIGHLY miss aiming with my mouse. Trying to aim with the PS4 controller is horrendously primitive, inaccurate and frustrating. I know the guys who make the Xim4 adapter for connecting keyboard/mouse are most likely making a killing, and they have to manufacture hardware, which you don't! Anyhow keep up the good work and hope word gets out.

komefai commented 6 years ago

@spinedoc777 Thank you so much for the kind words! My goal is to make this project free and open source so I will definitely keep it this way in the future (though paypal donations are welcome).

  1. Can we remap buttons to keys such as arrow keys on the keyboard? I tried but it seems Remapper only takes letters. Years of using arrow keys instead of WASD. I suppose same question for other keys which I use a lot such as Delete, Page up/down, and number keys on the keyboard number pad, etc.

Yes you can map it to every single key on your keyboard (alt+tab not recommended for obvious reasons). I actually forgot to put this in the README but you can use the Member name from this table provided by Microsoft. So for example the up arrow is just simply "Up" and "PageDown" for the PAGE DOWN key.

  1. Can we stretch the Remapper window to be larger? I have a 2nd screen that I put the Remapper screen on so I can remember all the remaps, but I can only see about 1/3 of them. I'd love to stretch the window longer so I can see all the remaps/commands.

I use multiple monitors and I have this problem as well, I'll see what I can do about that in the next version.

Also thank you for testing the debug build and the reporting your results. Please stay tuned for more updates!

Y-T-G commented 6 years ago

@komefai Does MouseSpeed only stay in the range -1 to +1 ? How did you settle on "127" as the factor for multiplication?

komefai commented 6 years ago

@Y-T-G MouseSpeed was intended to stay in [-1, 1] range which can be normalized to [0, 255], but since we have to linearly decay the speed over time to smooth the movements (rather than stopping immediately when the mouse stops) the range cannot be limited within [-1, 1] range. This makes [-infinity, infinity] its true range (depending on how fast the mouse moves and the sensitivity factor).

To answer your second question, the number 127 had to be used because of the substitution example I gave you in my previous post. In simple terms, the analog stick has to be centered when MouseSpeed is 0, has to be far left/up when MouseSpeed is <= -1, and has to be far right/down when MouseSpeed is >= 1. As long as these conditions are satisfied, the value could be anything because it will be clamped to [0, 255] range anyway.

I hope that answered your question :D

Y-T-G commented 6 years ago

@komefai I found out that the aim bouncing issue is caused by the if statement in this block:

if (Math.Abs(MouseSpeedX) < MouseDeadzone || Math.Abs(MouseSpeedY) < MouseDeadzone)
                        {
                            // Reset mouse speed
                            MouseSpeedX = 0;
                            MouseSpeedY = 0;
                            // Start release timer
                            if (MouseReleaseTimer == null)
                            {
                                MouseReleaseTimer = new System.Timers.Timer(MouseReleaseDelay);
                                MouseReleaseTimer.Start();
                                MouseReleaseTimer.Elapsed += (s, e) =>
                                {
                                    // Recenter cursor
                                    RemapperUtility.SetCursorPosition(500, 500);

                                    // Reset cursor overflow
                                    CursorOverflowX = 0;
                                    CursorOverflowY = 0;

                                    // Stop release timer
                                    MouseReleaseTimer.Stop();
                                    MouseReleaseTimer = null;
                                };

                            }
                        }

because of the OR operator in the condition. So if one of them returns true BOTH MouseSpeedX and MouseSpeedY is reset to 0.

I have tried putting them in seperate if statements and issue dissappears.

komefai commented 6 years ago

@Y-T-G Thanks again for your great work! I'll compile all of your suggestions into the next build. Working on some of it now.

komefai commented 6 years ago

@Y-T-G In the latest build, I've fixed many of the cursor bouncing/recentering issues. I've also slightly modified your code for calculating rx and ry into a "Deadzone" variable (defaults to 14.25, taken from your values of 142.65 and 113.25). The old deadzone has been renamed to "Decay Threshold" and "Release Delay" has been removed completely. A little messy now but works much smoother thanks to you!

Here's the merged code:

double positiveSpeed = 128 + MouseAnalogDeadzone;
double negativeSpeed = 128 - MouseAnalogDeadzone;
double rx = ((MouseSpeedX > 0) ? positiveSpeed : ((MouseSpeedX < 0) ? negativeSpeed : 128)) + (MouseSpeedX * 127);
double ry = ((MouseSpeedY > 0) ? positiveSpeed : ((MouseSpeedY < 0) ? negativeSpeed : 128)) + (MouseSpeedY * 127);
byte scaledX = (byte)((rx < min) ? min : (rx > max) ? max : rx);
byte scaledY = (byte)((ry < min) ? min : (ry > max) ? max : ry);
Y-T-G commented 6 years ago

@komefai Nice. I posted about this project in Wololo.net. Hoping to see more activity in here.

Y-T-G commented 6 years ago

@komefai Some kind of a bug in latest build MouseSpeed suddenly jumps to more than 200x EDIT: Looks like it is caused by excluding this line: RemapperUtility.SetCursorPosition(tmpX, tmpY);

Y-T-G commented 6 years ago

@komefai Are you planning on implementing an acceleration feature?

komefai commented 6 years ago

@Y-T-G I might have to scale the speed down again or use milliseconds instead of seconds for delta time. However, I don't think I will include RemapperUtility.SetCursorPosition(tmpX, tmpY); in future builds because it may cause the cursor to bounce around in opposite directions when reaching the end of the screen. Is it possible for you to scale it back down using the sensitivity setting?

Using acceleration instead of velocity might improve the movements, I'll look into it. Let me know if you have any suggestions on how it should be implemented.

Y-T-G commented 6 years ago

@komefai After disabling cursor hiding, I can see that this exponential jump in sensitivity happens as soon as the mouse cursor hits the border of my screen.

because it may cause the cursor to bounce around in opposite directions when reaching the end of the screen.

I am not experiencing aim bouncing with this line included in the latest build. Wasn't the issue due to deadzone threshold which was setting both MouseSpeedX and MouseSpeedY simultaneously to 0 in previous builds?

Y-T-G commented 6 years ago

As for acceleration, I tried this:

int signX = Math.Sign(MouseSpeedX);
int signY = Math.Sign(MouseSpeedY);
double rx = ((MouseSpeedX > 0) ? positiveSpeed : ((MouseSpeedX < 0) ? negativeSpeed : 128)) + (signX * (MouseSpeedX * 25) * (MouseSpeedX * 127));
double ry = ((MouseSpeedY > 0) ? positiveSpeed : ((MouseSpeedY < 0) ? negativeSpeed : 128)) + (signY * (MouseSpeedY * 25) * (MouseSpeedY * 127));

I didn't test with many values other than 25. It works but you might have a neater way to do it. I have remapper sensitivity scaled down by 10000 and decay rate at 1.01 with in-game sensitivity maxed out.

SD777x commented 6 years ago

Testing out the latest build, some weird stuff going on. Firstly I can't get it to work anymore, although I was having this issue with the last build towards the end as well. I start the PS4 remote play program, then I start PS4macro and it seems to inject remote play just fine in that the message changes same as if I connected a controller. I open remapper and press Z to start remote play but that doesn't work anymore so I just press start and nothing gets connected. PS4 remote play starts, my game streams, but I can only use the arrow keys which are used without ps4macro anyway.

Some notes; -in my xml file I have autoinject off because it never worked before when it was on -I don't have a PS4 controller so I say true for emulation, it worked perfectly like this before -I have the issue whether I run a custom settings.xml file or not -When looking at task manager it seems it's using the 32bit injection, my system is fully 64bit

Now some weird stuff, it seems even after closing PS4macro and the remote play program my keyboard is still taken over. I lose most of my keys, where the letter keys for example work as Alt-letter. I can't figure out how to turn this off other than re-logging, although once I simply pressed Alt and a letter and it seemed to fix the keyboard. So somehow it seems PS4macro is remaining in the background and tying up the keyboard, or some other issue.

I'm still trying to get it to work, I was very excited to see the new build and all the new stuff. Thanks also to Y-T-G for providing his input. I wish I was as technical as you 2 guys, but I can at least provide the feedback from a regular joe point of view.

SD777x commented 6 years ago

OK after trying a few times I got it to work, I have no idea how I got it to work though. Some more observations:

-Remapper seems to work when Enable Mouse is NOT checked. If I check Enable Mouse then remapper stops working and mouse look doesn't ever work, I did make sure to click back on the PS4 remote window for focus. If I uncheck Enable mouse then remapper works again.

-With mouse enabled or not enabled the ps4 remote app still sees the mouse as its default, which is to bring up the PS menu and be able to click on the PS menu.

-I'm still getting that issue where my keyboard stays in remapper mode, it seems random so far though although mostly the Enable mouse check seems to make it happen. I can now fix it by hitting Alt-E, although any Alt-letter combo may work, I'm not sure.

Y-T-G commented 6 years ago

@spinedoc777 I have posted a guide in here: https://github.com/komefai/PS4Macro/issues/8 . Did you try that?

SD777x commented 6 years ago

Thank you, I did finally get it to work. Not sure how. But mouselook is only going in one direction, no matter where I turn the mouse. Looking at the remapper mouse representation it seems mouselook is only going down and to the right, so my camera just goes around in circles.

Y-T-G commented 6 years ago

@spinedoc777 Which version are you using?

SD777x commented 6 years ago

2ec5033

komefai commented 6 years ago

@Y-T-G Thanks again for your input on acceleration I'll check it out.

@spinedoc777 I can also confirm your issue on mouse input remapping to one direction. It seems to be related to multiple monitor setup, caused by recentering the cursor to x=500, y=500 when remote play is focused. I'll fix it in the next build but a temporary fix for me is to do the entire process in my primary monitor.

SD777x commented 6 years ago

Yeah I do have multiple monitors. I tried it making sure the ps4macro and remapper were on the same monitor as the ps4remote play, but still the same issue where the mouse doesn't function and when it's checked on remapper stops remapping keys. I'll keep playing with it as time allows.

Y-T-G commented 6 years ago

@komefai Here's a lot better one for acceleration if you wish to try:

int signX = Math.Sign(MouseSpeedX);
                    int signY = Math.Sign(MouseSpeedY);
                    double rx = ((MouseSpeedX > 0) ? positiveSpeed : ((MouseSpeedX < 0) ? negativeSpeed : 128)) + (signX * Math.Abs(500 * MouseSpeedX * (MouseSpeedX * 127)));
                    double ry = ((MouseSpeedY > 0) ? positiveSpeed : ((MouseSpeedY < 0) ? negativeSpeed : 128)) + (signY * Math.Abs(500 * MouseSpeedY * (MouseSpeedY * 127)));

Although, the only thing changed is the value 25 to 500. Remapper settings: Sensitivity: 0.15 (as I said before, scaled down by 10000 in code), Decay Rate: 1.01 , Decay Threshold: 0.14, Deadzone: 14.65. In-game sensitivity maxed out.

jdorman12 commented 6 years ago

Has anyone fixed the mouse centering or shuddering? And sorry for asking but I couldn't figure out how to add these acceleration settings, I'm kind of new to this.

Y-T-G commented 6 years ago

@jdorman12 What issue are you having with Remapper?

And sorry for asking but I couldn't figure out how to add these acceleration settings, I'm kind of new to this.

These are source code changes. You need to make this changes to the Remapper.cs file and compile the Project in Visual Studio. Besides, these are just suggestions for the dev. You need to wait until acceleration gets implemented by dev himself.

jdorman12 commented 6 years ago

Honestly for me, everything is working fine except the acceleration settings for excessive movement of the mouse. Also I found that build c43db4 that you have to enable the remapper mouse settings in game, or awhile after ps4 video was displayed. Also just a question but would the decay rate and threshold have to be divisible by the frame rate of ps4 or hertz of the mouse? Just asking questions, keep up the good work! This is getting me excited about getting back into programming.

Y-T-G commented 6 years ago

@jdorman12 I am not sure if there is any relation between the hertz of the mouse and decay rate. Decay rate is to smoothen the emulated joystick movements. So, if you find the mouse movement not smooth, you decrease it down.

komefai commented 6 years ago

@Y-T-G Thank you, and sorry for the slow response. I've been very busy working on a job that requires rented hardware, so I have to focus on it for the past week. I'll try your new code over the weekend and hopefully release another build.

@jdorman12 The decay rate can be anything greater than 1.

silentnailgun commented 6 years ago

@komefai Great work! I've been testing all your releases and noticed that sometimes when I have the PS4Macro open the buttons start flickering (they kinda have their signal interrupted) either when I use the DS4 or the keyboard. Closing the PS4Macro makes the DS4 works properly. Any ideas?

Y-T-G commented 6 years ago

@komefai Is there a way to save the Mouse settings in Remapper?

komefai commented 6 years ago

@silentnailgun Thank you! It seems like PS4 Macro could not complete the execution within the required time. What are your PC specs?

@Y-T-G Yes, I'll add all of the mouse settings in BindingsContainer class so that it will be saved along with keyboard mappings (by clicking on the "Save Bindings" button).

silentnailgun commented 6 years ago

@komefai I’m using a Surface Pro 4 (i5, 8GB) with Windows 10. It’s weird that it used to work pretty smooth later, but now It happens with any version that I use.

komefai commented 6 years ago

@silentnailgun I think you should try it without a controller (set EmulateController to true in settings.xml). It should be smoother because there will be no hardware delay in an emulated controller.

komefai commented 6 years ago

@Y-T-G Your acceleration code is working well in GTAV (first person). The decay is kicking in really nicely with the changes applied. I'm using Sensitivity=0.20 by the way.

I'll expose the value 500 in the UI and make it adjustable and I'll also implement save/load for mouse settings. Thanks again for your great work!

sarmadh17 commented 6 years ago

thank you problem slow sensitive mouse play rainbow six siege how to fix adjustable settings code

komefai commented 6 years ago

@sarmadh17 Hi, I'll release an update for that soon.

PS4Macro_658584b.zip

komefai commented 6 years ago

@Y-T-G In this commit I've applied the changes suggested by you and exposed the "500" value as "Makeup Speed" in the UI. I also scaled the sensitivity down to 100,000 instead of 10,000 in code so your sensitivity should now be 1.5 instead of 0.15. Save/load for mouse input settings has been implemented, but if you get any errors just delete the old bindings.xml file and save a new one.

PS. I'm releasing an update build soon. Sorry for the slow responses lately :(

TamaKaiNya commented 6 years ago

Been testing with Sword Art Online: Fatal Bullet. Mouse movement still seems shaky and the program doesn't hook on to the remote play program on the first try. I have to try two times for it to recognize my keyboard and mouse. Also, adding a keyboard shortcut to toggle the microphone on and off would be handy if that's even possible. Keep up the good work.

SebaPJ commented 6 years ago

Great application. After a few tests with the mouse, I noticed the problem that the application does not read the full mouse movements but only move x and y, but always only one at a time. It means. Smoothly moving diagonally up to the right means moving only up or just right. In addition, the mouse pointer jumps, which deprives it of all precision (I tried to manipulate the sensitivity and output of dpi on the mouse but it has not changed). Tested using "destiny".

I see the same problems in any fps game

TamaKaiNya commented 6 years ago

@SebaPJ I have the same issue. setting sensitivity to 20 helped me a bit

SebaPJ commented 6 years ago

@TamaKaiNya a bit :P But I noticed that there is no smooth joystick (mouse pointer) movement. As if the joystick had only options max left, max right, max top and max bottom and center. Movement to the right with the mouse means, for a given period of time, moving the joystick to 100% to the right and returning to the middle setting. I think that this can cause the above problem.

SebaPJ commented 6 years ago

@komefai in my opinion to fix above issue you have to read mouse movement speed and fit joystick movement to this. If I move the mouse fast to the right, the joystick should be fully moved right. If I move mouse slowly, the degree of the joystick knob should be scaled to the speed of the mouse. This option also requires mouse resolution support in settings.