Requesting help with specific Mouse to Joystick script.

Ask gaming related questions (AHK v1.1 and older)
Sylvenia
Posts: 8
Joined: 10 Sep 2018, 16:11

Requesting help with specific Mouse to Joystick script.

12 Sep 2018, 00:07

So it may sound strange but......

What i'm looking for is a script that sets my mouse to the middle of the screen as a neutral x0/y0 position. when i move my joystick, the mouse will move relative to the position of the joystick. My aim for this is to use it for Sacred 2 Gold edition. The idea is this: on console, when you approach an enemy/NPC/chest/etc... you can just push the button and talk without necessarily targeting. My thought is, if the mouse is confined within the vicinity around my character, then targeting is achieved by running my character to what i want to what i want to interact with and push the A button (Left click).
User avatar
Onimuru
Posts: 107
Joined: 08 Sep 2018, 18:35
Contact:

Re: Requesting help with specific Mouse to Joystick script.

12 Sep 2018, 01:31

This is untested but how I would do it:

Code: Select all

SendMode Input
SetTitleMatchMode, 2
CoordMode, Mouse, Screen

If !WinExist("ahk_class x")	;Replace x with the correct class as seen by mousing over with windows spy.
	WinWait, ahk_class x
WinActivate, ahk_class x

Center_x := (A_ScreenWidth //2), Center_y := (A_ScreenHeight //2)

Exit

*$f::		;Change f to your interact key.
	MouseMove, %Center_x%, %Center_y%
	Send f
	Return

;x::			;Alternative way to save Class to replace x above, press x while the game is active.
;	WinGetClass _w, A
;	ToolTip, % _w
;	Clipboard := %_w%
;	Return
Sylvenia
Posts: 8
Joined: 10 Sep 2018, 16:11

Re: Requesting help with specific Mouse to Joystick script.

12 Sep 2018, 12:07

So I tested the script, and I'm unsure if I'm either doing something wrong or the script doesn't work. I took the script and put it in a text document and changed it to .ahk. I ran the game and double clicked the .ahk file to run the script. Nothing seems to happen. I'm new with this type of scripting so it's possible I'm just not doing something correctly. I do appreciate the response.
User avatar
Onimuru
Posts: 107
Joined: 08 Sep 2018, 18:35
Contact:

Re: Requesting help with specific Mouse to Joystick script.

12 Sep 2018, 14:19

Right click your desktop and create a new AHK file then edit and paste your code inside. Run as admin and make sure you have an AHK icon on your task bar to tell if it's running! You need to modify the code as well, read my comments.
Sylvenia
Posts: 8
Joined: 10 Sep 2018, 16:11

Re: Requesting help with specific Mouse to Joystick script.

12 Sep 2018, 20:41

Ok so I did what the comments say. It does do partially what i want, it moves the mouse to the center of the screen. I was hoping to be able to control the mouse with my joystick on my Xbox One gamepad as well. I've seen the script that allow you to move your mouse with a joystick, but they don't quite do what I'm looking for; they allow you to move the mouse up, down, left and right as you move the joystick. What i'm looking for is; I want the mouse to stay stationary in the center of the screen if i'm not touching the joystick (neutral x0/y0) and if i move the joystick, the mouse moves in relation to where i move the joystick. so if i push the joystick down, the mouse moves down and when i release the joystick it moves back to the middle. or if i push the joystick up and to the right, the mouse moves the same. the idea is that i can move the mouse in a circle around my character in close proximity to my character. i do hope i'm not being too picky because i really do appreciate the help.
Sylvenia
Posts: 8
Joined: 10 Sep 2018, 16:11

Re: Requesting help with specific Mouse to Joystick script.

12 Sep 2018, 20:50

so here's a visual representation of what i'm looking for. imagine that my character is standing in the center of the box in this video and the mouse is the +
https://youtu.be/CxlxlgKqyow
User avatar
Onimuru
Posts: 107
Joined: 08 Sep 2018, 18:35
Contact:

Re: Requesting help with specific Mouse to Joystick script.

13 Sep 2018, 06:45

Ok, I see I misunderstood you originally. I have no experience with using a controller so I googled it and there was a script already made so this is almost entirely someone else's code, I just made a small addition at the end to reset the cursor to the center of the screen. Obviously I can't test this but it looks like it should do exactly what you want. Read the comments and adjust the variables to your preference.

Code: Select all

Coordmode, Mouse, Screen
SetBatchLines, -1

;Increase the following value to make the mouse cursor move faster:
JoyMultiplier = 0.30

;Decrease the following value to require less joystick displacement-from-center
;to start moving the mouse.  However, you may need to calibrate your joystick
;-- ensuring it's properly centered -- to avoid cursor drift. A perfectly tight
;and centered joystick could use a value of 1:
JoyThreshold = 3

;Change the following to true to invert the Y-axis, which causes the mouse to
;move vertically in the direction opposite the stick:
InvertYAxis := False

;If your system has more than one joystick, increase this value to use a joystick
;other than the first:
JoystickNumber = 1

;Calculate the axis displacements that are needed to start moving the cursor:
JoyThresholdUpper := 50 + JoyThreshold
JoyThresholdLower := 50 - JoyThreshold
If InvertYAxis
    YAxisMultiplier = -1
Else
    YAxisMultiplier = 1

SetTimer, WatchJoystick, 10  ;Monitor the movement of the joystick.

GetKeyState, JoyInfo, %JoystickNumber%JoyInfo

Return

WatchJoystick:
	MouseNeedsToBeMoved := False  ;Set default.
	SetFormat, Float, 03
	GetKeyState, JoyX, %JoystickNumber%JoyX
	GetKeyState, JoyY, %JoystickNumber%JoyY
	If JoyX > %JoyThresholdUpper%
	{
		MouseNeedsToBeMoved := True
		DeltaX := JoyX - JoyThresholdUpper
	}
	Else If JoyX < %JoyThresholdLower%
	{
		MouseNeedsToBeMoved := True
		DeltaX := JoyX - JoyThresholdLower
	}
	Else
		DeltaX = 0
	If JoyY > %JoyThresholdUpper%
	{
		MouseNeedsToBeMoved := True
		DeltaY := JoyY - JoyThresholdUpper
	}
	Else If JoyY < %JoyThresholdLower%
	{
		MouseNeedsToBeMoved := True
		DeltaY := JoyY - JoyThresholdLower
	}
	Else
		DeltaY = 0

	If MouseNeedsToBeMoved
	{
		SetMouseDelay, -1  ;Makes movement smoother.
		MouseMove, DeltaX * JoyMultiplier, DeltaY * JoyMultiplier * YAxisMultiplier, 0, R
	}
	;If the mouse doesn't need to be moved:
	Else
		MouseMove, (A_ScreenWidth //2), (A_ScreenHeight //2), 0		;Move mouse instantly to center.
	Return
You might want to link this to the game window with #IfWinActive ahk_class [gameClass] or build a toggle or your mouse will forever return to the center.

Code: Select all

^x::SetTimer, WatchJoystick, % ((Toggle_Variable := !Toggle_Variable) ? 10 : "Off")	;Ctrl + x to toggle on/off
Sylvenia
Posts: 8
Joined: 10 Sep 2018, 16:11

Re: Requesting help with specific Mouse to Joystick script.

13 Sep 2018, 22:00

OK so i tried this new script and it keeps crashing (or closing, not sure). i even tried running it as Administrator but no go.
User avatar
Onimuru
Posts: 107
Joined: 08 Sep 2018, 18:35
Contact:

Re: Requesting help with specific Mouse to Joystick script.

14 Sep 2018, 08:46

I can’t help you any further, I suggest you read the sticky on this sub forum reference controllers or google it, I got a ton of hits.
Sylvenia
Posts: 8
Joined: 10 Sep 2018, 16:11

Re: Requesting help with specific Mouse to Joystick script.

14 Sep 2018, 12:11

ok well thank you for the help.
Sylvenia
Posts: 8
Joined: 10 Sep 2018, 16:11

Re: Requesting help with specific Mouse to Joystick script

17 Sep 2018, 10:43

Welpemarp wrote:Thats gonna be a Problem Because most games reduce walking speed and your FoV when you toggle iron sight. So it would be unplayable. Maybe with some moding you could change this, but then again i.e in Bioshock Infinte Weapons become way more accurate when you use iron sight at least thats what i feel.
Actually i wasn't planning on playing shooter games with this script so that's OK with me. I want to use it to play dungeon crawlers like Diablo 2 or Sacred 2.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 65 guests