fqlx / XboxKeyboardMouse

Keyboard and mouse for Xbox One streaming on Windows
Apache License 2.0
317 stars 66 forks source link

Changing the button mapping #6

Closed ralogsdon closed 7 years ago

ralogsdon commented 8 years ago

First i would like to say that is project is amazing, i recently had an accident at work and it has rendered my right thumb useless for controller gaming, so this project of yours has saved me from throwing out my Xbox. now i have been digging through the files, and i am completely clueless on all this, but i found one file that i thought would changed the key mapping, but it never worked. Could you walk me through exactly what i need to do to do this?

fqlx commented 8 years ago

The file you are looking for is TranslateKeyboard.cs Load up the project in VS and compile after you edit it. If you have no idea what you're doing let me know

ralogsdon commented 8 years ago

lol i have no idea what i am doing, but i will try to figure it out with your help.

ralogsdon commented 8 years ago

Is VS Microsoft Visual Studio?

ralogsdon commented 8 years ago

so i opened the solution file with visual studio, and edited the files i wanted now what do i do next?

fqlx commented 8 years ago

For example on line 23 in TranslateKeyboard.cs { Key.Space, X360Buttons.A }, Maps the space bar to the A button

If you change Key.Space to Key.Y it maps the A Button to the Y on your keyboard.

Then hit the green play button to run/debug the app on your computer.

ralogsdon commented 8 years ago

right now im dealing with another issue, my computer just updated and now i get the spc bus error, before the update everything was fine.l

ralogsdon commented 8 years ago

idk what to do, i just keep getting this error, and this is with an un edited version, the one i was using to play xbox with earlier today untitled untitled2

fqlx commented 8 years ago

Reinstall SCP. If you can't get it to work I'll just make you a build later tonight.

ralogsdon commented 8 years ago

well i got everything working fine. had some issues with drivers for some reason, but i am able to re map all keys and use it just fine. just sucks some keys cam't be used. but this is a great temporary fix until i get my hands on a Xim4. Thanks again man.

ralogsdon commented 8 years ago

One more thing, how do you have yours set, i keep trying and trying but my mouse likes to jerk sometimes or it doesn't like to stop when i stop moving, or is that apart of the early stages of development?

fqlx commented 8 years ago

Mapping the mouse to the right stick is the hardest problem of this whole project. :) I've had ideas to normalize and sample the mouse movement but haven't gotten around to updating anything. Unfortunately I probably won't update it anytime soon and I figured if someone really cared they would push out a better solution.

You can try playing around with the tick count or use a faster computer.

fqlx commented 8 years ago

And keep in mind there's 50-80ms input lag with a hardwired direct connect to your Xbox. If you're using wireless, it will be unplayable. There's no way to reduce that lag.

AndreYin commented 8 years ago

I have a wireless connection and I have to say, this works perfectly on it (apart from the mouse, of course).

ralogsdon commented 8 years ago

Hey man, just wanted to say thanks again, this app has been amazing for me being crippled an all, lol. But i broke down and bought one of the devices that do pretty much the same thing only because the app shuts off in the middle of me streaming because the app sucks, and because ive shuts my mic off for some reason. anyway bro, great work!

fqlx commented 8 years ago

I'm surprised it shuts off in the middle and kills your mic, oh well. And the Xim4 should be superior (I've never used) and even better than using a controller. This app started out as a concept for another project I was working on some I figured I'd share it. And to honest, I'd never use it for any competitive gaming ever. The streaming is too laggy and the mouse translation are impossible for a FPS Anyways I'm glad it helped you until your Xim got in.

fqlx commented 8 years ago

Try this:

  1. Run ScpToolkit Settings Manager
  2. Use asynchronoous HID Report Processing
  3. Disable Rumble and Native Feed
MattMistele commented 8 years ago

Hey - I've downloaded your code and I've been working to get the mouse to work properly. It's a work in progress, but I've got it to work much better than it did before.

The two issues I see with the current code of the mouse to joystick are:

1) The loop - I'm not sure if it's just me, but the loop was running irregularly for my computer. This caused the 'jaggedness' of no matter what you set your tick rate to, the loop wouldn't be fast enough to update smoothly, causing the slow, sporadic movements when looking around in an FPS. To fix this, I did a little 'Band-Aid' patch for now, using an integer to count down from a number like 30000. (Not final, just to make it smooth for the time being. Prob going to use a timer in the future).

2) Now that I've got a good enough smooth loop for the mouse to work for now, I noticed that you just set the joystick inputs to 100%, no matter how far the mouse has moved. I'm a little stuck, but I'm working on an algorithm to convert how far the mouse has been moved to how much pressure should be put on the joysticks. (Right now I'm just multiplying the mouse input by 500 then putting it into the joystick, which makes for a workable workaround, but it's not precise enough to want to play FPS's where you want on point accuracy with yet.)

So far, this is an awesome program, and amazing work so far on everything else. Hopefully at some point we can get this program to work as a great alternative to playing games on the Xbox with a mouse/ keyboard (its free)!

You could probably make a new branch or something for me to push my changes to if you wanted to see the code.

fqlx commented 8 years ago

1) I'm not sure about this behavior. I haven't noticed that.

2) Yes, setting the joystick to max is a terrible idea.

An idea I've been thinking about is first we normalize everything between 0 - 1.

scaledValue = (rawValue - min) / (max - min); E.g. = The joystick values 127.5 would equal .5.

And then we build a table of the last 100 values/movement and normalize them all.

I'm not sure if this the best way to do it, but it's definitely better than the current code.

MattMistele commented 8 years ago

1) That's funny - maybe it differs between computers or something, but when I originally downloaded and tried the program, the mouse movement was very choppy and jagged. Maybe we can do something to normalize it between computers - honestly though I don't know where the problem was coming from - the stopwatch solution should work.

2) If I'm reading this right, you want to convert the mouse difference to be between -1 and 1 then scale that to short.min and short.max to put into the controller? It might be easier because scaling between -1 and 1 is easier than scaling between short.min and short.max.

Not sure I understand about building a table of values - would that be for reference (E.g. if I move the mouse X much it should be Y pressure on the stick?)

fqlx commented 8 years ago

Yea so we make it between 0-1 and then denormalize it back into 0-255. By building the table of values we can get a range of average mouse movements. So right now it the code just checks what direction and sets the controller to 255 (MAX). I think by building a table of the distance between those directions and getting the range we can map the table normalized values to the controller normalize values (or closest match).
Another idea is somehow getting the acceleration/velocity from the table as well and translating that. I dunno, I should have paid more attention in calculus.

MattMistele commented 8 years ago

I don't think that getting a table of values would be a good idea - all that does is lose precision. From what I can tell, there's a couple steps in this process.

1) Calculate how much the mouse has moved (already done with xDifference)

2) Take the difference and put it into a value between 0 and 1.

These numbers are made up - but here's the theory: We will set a constant max value the mouse can move to translate to max pressure on the joystick. Say this value is 10 - if the user moves the mouse more than 10, then the value will be set just as 10 (you cant move a joystick more than physically possible, it has to have a max value. The mouse can reach this value by moving 10 / faster). If the mouse moves less than 10 (say 5), the joystick pressure will be set as half. We can then convert these numbers to be between 0 - 1. (.5 for the example).

3) Now that we have our value between 0 - 1, all we need to do is just convert it to be between 0 and short.Max.

Here, all we need to do is just multiply by short.Max. E.g. 0.5 * short.Max should give us half pressure on the joystick.

4) Plug that value into the controller to get the correct sensitivity and look movement.

At no point should we need a table of values - we can do this all with math in code.

MattMistele commented 8 years ago

Hey - I forked your repository to upload some of my changes that fixes the mouse (mostly). https://github.com/MattMistele/XboxKeyboardMouse

It's still a work in progress, but now I'm using a timer (not a stopwatch) to run the loop. This works better for my PC. I've set the interval to run every 50ms, but I'll later add the option to change the interval. (Something you've already got with the stopwatch though).

I took your idea and now I'm normalizing the mouse inputs to be between -1 and 1, then I'm converting it to be between short.Min and Short.Max to run the mouse. It runs a lot smoother with more precision, but there's still more work to do to get it 100%.

I also cleaned up the code a little bit because now I'm using a timer.

Later, I plan to add the ability to map the buttons in the program and pin the mouse precision down 100%

Regards, Matthew

fqlx commented 8 years ago

Awesome man! When you feel like it's ready, do a pull request.

klemensgraf commented 8 years ago

First: It is an awesome tool! Thanks mate!

Second: I have a problem with changing the keys. I will change the start button key from "~" to the key "P" but I failed always.

I have MS Visual Studio but I'm not very skilled in programming. I hope you can help with this.

Regards Klemens

CallumCarmicheal commented 7 years ago

@ralogsdon I have implemented a button mapper, this should solve the issue for end users wanting to change the button mappings. You can download the new version here