Mouse Movement to Controller stick/keyboard keys

Post gaming related scripts
crisangelfan
Posts: 9
Joined: 24 Jul 2016, 20:13

Mouse Movement to Controller stick/keyboard keys

24 Jul 2016, 20:31

I would like a script that will allow me to map the movement of my mouse to that of the WSAD keys on my keyboard or, the more preferable option, the movement of the left analog stick of a connected Xbox One controller. Thanks for the help
Helgef
Posts: 2391
Joined: 17 Jul 2016, 01:02
Contact:

Re: Mouse Movement to Controller stick/keyboard keys

25 Jul 2016, 12:04

If I have time tonight I'll make something, shouldn't be a problem.
Helgef
Posts: 2391
Joined: 17 Jul 2016, 01:02
Contact:

Re: Mouse Movement to Controller stick/keyboard keys

25 Jul 2016, 16:36

Here is a simple joystick simulator, add whatever functions you want it to perform. See comments in code, it's pretty straight forward.

Source code:

Code: [Select all] [Expand] [Download] (Untitled.ahk)GeSHi © Codebox Plus



Put image in same folder as script, run.
mouse2joystick.ahk
(3.88 KiB) Downloaded 92 times

circle.png
circle.png (2.91 KiB) Viewed 2267 times
crisangelfan
Posts: 9
Joined: 24 Jul 2016, 20:13

Re: Mouse Movement to Controller stick/keyboard keys

25 Jul 2016, 18:34

I'm having a bit of trouble getting it all to work. Sorry, this is my first time using AutoHotKey and I'm not sure if I am doing something wrong or what. I've tried every key I can imagine to enable the toggle and I can't get it to work. I've got the picture appearing on screen, but my mouse doesn't lock to it. Thanks for your help as well Helgef.

edit# I found the correct key bind literally right after I typed that message and I am getting ready to test this script out. I really appreciate your help with this Helgef. Thanks so much.
crisangelfan
Posts: 9
Joined: 24 Jul 2016, 20:13

Re: Mouse Movement to Controller stick/keyboard keys

25 Jul 2016, 19:56

I tested the script in a Custom match in Call of Duty Black ops 2 and I could not get the effect I needed with this script. I want to be able to move the mouse along the x and y axis and have those correspond to those of which the player would be making in game. Thanks again
Helgef
Posts: 2391
Joined: 17 Jul 2016, 01:02
Contact:

Re: Mouse Movement to Controller stick/keyboard keys

26 Jul 2016, 01:56

First, did you modify the action() function? It just shows tooltips, you need to add your key presses there. Eg, under the first block, segment 12 and 1, you add press down your right movement key, also release previously pressed keys.
crisangelfan
Posts: 9
Joined: 24 Jul 2016, 20:13

Re: Mouse Movement to Controller stick/keyboard keys

26 Jul 2016, 13:57

I hadn't at the time, but I have now and I got the WSAD keys mapped to the corresponding segments. I opened NotePad to test the keystrokes and I noticed there was often the D key pressed when the mouse went in between segments 8 and 9 I believe. I have D set to segments 1 and 12, 2, and 11. When I tested the script in Call of Duty, I couldn't move and there was a slight mouse drift off to the left even with the Sensitivity set to 0.01, it seemed to move faster than that. I'm not sure if that's something with the game, the script, or the fact that when I toggle the script on, I have to click on the game screen behind the Circle picture. I also have a small request to make and I'm not sure how much trouble it would be, I would like for the mouse cursor to be reset back within the center of the circle as soon as the movement stops. For the use of the script, this will be a crucial part. Thanks again for all your help and I apologize if I'm asking for a lot.
Helgef
Posts: 2391
Joined: 17 Jul 2016, 01:02
Contact:

Re: Mouse Movement to Controller stick/keyboard keys

26 Jul 2016, 16:23

If you post your code I can look at it.
crisangelfan
Posts: 9
Joined: 24 Jul 2016, 20:13

Re: Mouse Movement to Controller stick/keyboard keys

26 Jul 2016, 17:08

The code isn't changed much from what you gave me, all I really did was, since I couldn't figure out how to keep the ToolTip with the button press, change your "Tooltip, Right" code to "Send,D" but of course for the following directions and buttons[code]
mouse2joystick (1).ahk
(3.8 KiB) Downloaded 62 times
Helgef
Posts: 2391
Joined: 17 Jul 2016, 01:02
Contact:

Re: Mouse Movement to Controller stick/keyboard keys

26 Jul 2016, 19:28

I made some modifications. I tested it in quake 3 and it works fine, but quake does some funny things to the mouse, so I had too make some special adjustments for that, that's not in the script here though, the point is your game might require some special tweaking of the script, it will be hard for me to help since I don't have it.
I have added a hotkey #d - that is winkey+d - to enable/disable movment of the circle.
Also, moving back to the inner circle will send all (wasd) keys up, and mouse will fall back to the center. I adjusted your modifications to the action() function.
You should do this: Edit the variable gameExe in this script, read the comment, save, (if you want to test in notepad first, change gameExe:="notepad.exe") open your game, when its ready to play, run the script, press winkey+d, move the circle to where you want it, press winkey+d again, press winkey+s and hope it works.
If you have problems, the more info you can give, the easier it is to help.
Another thing to try if you have problems, put the circle over the center (approximately is fine) of the game screen, see what happens.

Code:
Spoiler
crisangelfan
Posts: 9
Joined: 24 Jul 2016, 20:13

Re: Mouse Movement to Controller stick/keyboard keys

26 Jul 2016, 20:28

I just opened the script and tested it out in Black Ops 2. I managed to get it to work "properly-ish". I still had the mouse drifting off to a key when I initially loaded the script, But at some point, and I'm not sure how, I got the drifting to stop altogether. I noticed that when i disabled the script, it would still be drifting off as if the key were still being pressed down. However, this time the drifting was slightly weird as my games camera was drifting to the right, but the mouse was "pressing" my A key and moving me to the left. Also, when I tried to move the circle around, the shortkey worked and I could move it properly, though the mouse seemed to be set to return to the center point of the initial location, ie the center of the screen.


This part is only for to the script and can be disregarded for now:I would like to enlarge the segments to reach to almost the center of the circle, that isn't especially important to the use of this script.
Helgef
Posts: 2391
Joined: 17 Jul 2016, 01:02
Contact:

Re: Mouse Movement to Controller stick/keyboard keys

27 Jul 2016, 08:25

Do you have the circle outside the game window? If so, if you move it from that side, to the other side, does that change the behaviour? The game is probably moving the mouse, or trying, and the script tries to move it back. A solution could then be to have the circle centered where the game wants it, probably center of game screen. Then the circle has to be made invisible or it will obstruct game play, and cursor should be hidden to.

Edit: You can change the radius of the inner circle via the ir parameter in the script, make it smaller, say ir:=50, then the segments are reached halfway out of the circle, from the center that is, you can also make outer circle smaller, that is r. Just make sure
ir<r.
crisangelfan
Posts: 9
Joined: 24 Jul 2016, 20:13

Re: Mouse Movement to Controller stick/keyboard keys

27 Jul 2016, 12:27

I'm not sure that I actually will need the circle to be invisible as I plan on doing all of this in VR, and I dont believe the circle will appear in the headset. Also, I got the joystick to work properly by adjusting the radius of the inner circle and offsetting the circle slightly to the right of the center of the screen; however, is there a way to delay the return of the mouse to the center.
Helgef
Posts: 2391
Joined: 17 Jul 2016, 01:02
Contact:

Re: Mouse Movement to Controller stick/keyboard keys

27 Jul 2016, 12:49

Ok that's nice. I don't know what that is, VR.
About the delay, yes, if you just want to stick the mouse to the center longer, adjust the fallbackpause parameter. Or add a, eg., sleep, 200 before the movemouse in the if (actiontaken =1) block. Typed on the phone..
crisangelfan
Posts: 9
Joined: 24 Jul 2016, 20:13

Re: Mouse Movement to Controller stick/keyboard keys

27 Jul 2016, 13:16

I'm not sure what happened, but now the mouse wont reset its position at all after it is moved.

Also, VR is Virtual Reality. I've just gotten a VR Head Mounted Display, sort of. I'm streaming a VR game from my PC to my Phone and playing it in the HMD. I've set up a gun control system using a Wii Mote and nunchuck synced to my PC via bluetooth, and this script is going to be used to translate my real world movement into the game allowing my real world movements to be translated to an in-game movement. There are alternatives to something like I am doing, but those solutions tend to get a bit pricey.

Here's my current script:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Helgef
Posts: 2391
Joined: 17 Jul 2016, 01:02
Contact:

Re: Mouse Movement to Controller stick/keyboard keys

27 Jul 2016, 15:24

Sounds really cool mate.
I see a problem right away, line 38-39, move them to line 58.
Edit: Can't think of anything else that would cause that, line 168 should be changed to something like this though:

Code: [Select all] [Download] GeSHi © Codebox Plus

x:=(x=0)?0.00001:x
This could actually cause getting in the wrong segment, I'm gonna see if I can get an error there.
Edit2; It's easy to get the error but it woudnt cause getting in the wrong segement due to the y variable be signifacntly larger, however if ir would be much smaller this could cause serious error. Better to correct it.
crisangelfan
Posts: 9
Joined: 24 Jul 2016, 20:13

Re: Mouse Movement to Controller stick/keyboard keys

31 Jul 2016, 23:37

Sorry for not responding to your post for a while, I've been away from my computer for a while and haven't messed with it since my last post. I'll try editing the script a bit and see what I can get.
User avatar
evilC
Posts: 3546
Joined: 27 Feb 2014, 12:30

Re: Mouse Movement to Controller stick/keyboard keys

03 Aug 2016, 07:29

My MouseDelta library has a sample script which maps mouse to WSAD

MouseGetPos is fundamentally flawed for mouse input of this type, as it stops producing meaningful results if the mouse cursor hits the edge of the screen. My MouseDelta code is immune to this problem.
Helgef
Posts: 2391
Joined: 17 Jul 2016, 01:02
Contact:

Re: Mouse Movement to Controller stick/keyboard keys

04 Aug 2016, 12:06

I'll check it out later. As for mousegetpos, in my script the mouse is supposed to be placed over a gui window. But this was more of a toy-script, I'm sure there are plenty of free software if one would bother to google instead of taking the easy way out and making it from scratch. Cheers.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 5 guests