Jump to content



Photo
- - - - -

Autohotkey script for analog nudging with gamepad/xbox controller

xbox controller gamepad Autohotkey nudging

  • Please log in to reply
4 replies to this topic

#1 magnasaver

magnasaver

    Hobbyist

  • Members
  • PipPip
  • 11 posts

  • Flag: ---------

  • Favorite Pinball: Black Knight

Posted 28 July 2020 - 10:21 AM

Here is a little Autohotkey script that can help you, if you want to use a gamepad or xbox contoller for analog nudging. As a bonus it also allows you to use the d-pad of your controller for your service buttons. Copy the code into an empty text file and rename it to whatever you like. JusT make sure it has the filename extension ".ahk". 

I have included all information of how to use the script in the comment section of the script:

;VpinballX is only configured to use accelerometers for nudging.
;Therefore I wrote this little script which converts the absolute data from joystick input to an accelertion value
;This script allows you to use the left (and right, if configured in script below) joystick of the gamepad controller for nudging in VPinballX
;Do not expect a completely realistic nudging behavior, because nudging with a controller will always be different from real nudging.
;
; 
; HOW to install and use this script:
; 
; - Download and install Autohotkey from www.autohotkey.com
; - Download and install vjoy from vjoystick.sourceforge.net
; - set up and configure a vjoy joystick
	; start "configure vJoystick" from the Windows start menu 
	; During the setup process of your vjoy: check "Slider" and "Dial/Slider2"
	; Keep all other axes unchecked
	; Confirm that your vJoy Device ID is 1
		;if it is not 1, change the vjoy_id in the "Settings" section of this script accordingly

; - Download VJoy_lib.ahk library FROM github.com/AHKScript/AHK-vjoy-Library and put this library file 
	;into the same folder together with this script
; - Change the setting in Visual Pinball:
		; Go to the "Preferences-Configure Keys,Nugde and DOF" section of Visual Pinball
		; and set "X Axis(L/R)" to "Slider 1"
		; and     "Y Axis(U/D)" to "Slider 2"

		;check "Enable Analog Nudge" and check "Tilt Sentitivity"
		; Uncheck "Legacy/VP 9 style...", "Enable Nudge Filter...", "Normal Board..." and "Acclerometer Rotation"

		; Set X-Max,Y-Max,X-Gain,Y-Gain and Tilt Sensitivity to whatever feels good for your purpose
		; 
		; To give you a good starting point for your tweakings, here are the values I currently use:
		;	X-Max.....100,Y-Max....100,X-Gain...60%,Y-Gain....60% and Tilt Sensitivity 860
		; Disclaimer: I am still experimenting with these values and I am by no means a pinball expert.
		;		So I am sure you can come up with better values by yourself.
		 
		

; - Once you have completed all steps above you can start this script by double-clicking on it. 
	;If you see now a green tray icon with a white "H" , 
	;you have sucessfully started the script and the script is running.
; Now you shoud be able to use your left joystick of the gamepad for nudging  

; TROUBLESHOOTING:
;                 For some reason the script occasionally may crash or not work properly. 
;                 In this case a restart of the script should help: 
;		   - right click on the green tray icon and choose exit 
;                  - then restart the script again by doubbleclicking the script file. 

; A bonus feature I have included:
; it sends service button keystokes, if you press the buttons of the D-pad of the gamepad. 
; This allows you to use the service buttons with your gamepad on most tables. 
; However, unfortunately you cannot press two service buttons at the same time with your D-pad. 
; In this case you can still use the keyboard. 
; If you want wo disable this feature, add ";" before "SetTimer, WatchPOV, 5" in the script below

; Happy pinballing!!!


;License Information: I do not care. Do whatever you want with this script.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.



;;;;;;;;;;;; SETTINGS ;;;;;;;;;;;;;;;
; Set the vjoy id of the stick to control
vjoy_id := 1
; Make sure your VJoy_lib.ahk script is in the same folder  
#Include VJoy_lib.ahk

; Enable (true) or disable (false) left-right nudging with right controller stick
leftJoystickNudge :=false

;;;;;;;;;;;;;;; END OF SETTINGS ;;;;;;;;;;;;;;

Starttimer:
SetTimer, WatchAxis, 15
SetTimer, WatchPOV, 5

OldX:=32767/2
OldY:=32767/2
OldZ:=0

; Init the vJoy stick
vjoy_init(vjoy_id)

Main:
goto Main

WatchPOV:
POV := GetKeyState("JoyPOV")  
KeyToHoldDownPrev := KeyToHoldDown  

if (POV < 0)   ; No D-pad keys
    KeyToHoldDown := ""
else if (POV > 31500)               ; Forward
    KeyToHoldDown := "7"
else if POV between 0 and 4500      ; Forward
    KeyToHoldDown := "7"
else if POV between 4501 and 13500  ; Right
    KeyToHoldDown := "9"
else if POV between 13501 and 22500 ; Down
    KeyToHoldDown := "vk0x30"
else                                ; Left
    KeyToHoldDown := "8"

if (KeyToHoldDown = KeyToHoldDownPrev) 
    return  ; Do nothing.

SetKeyDelay -1
if KeyToHoldDownPrev  
    Send, {%KeyToHoldDownPrev% up}  ; release
if KeyToHoldDown   
    Send, {%KeyToHoldDown% down}  ; press down
return

WatchAxis:
JoyX := GetKeyState("JoyX")*327.67
JoyY := GetKeyState("JoyY")*327.67
JoyZ := GetKeyState("JoyZ")*327.67

DeltaX:=JoyX-OldX+32767/2
DeltaY:=JoyY-OldY+32767/2
DeltaZ:=JoyZ-OldZ

if(leftJoystickNudge) 
{
	DeltaXZ:=DeltaX+DeltaZ
}
else
{
	DeltaXZ:=DeltaX
}

OldX:=JoyX
OldY:=JoyY
OldZ:=JoyZ

; Set axis value
VJoy_SetAxis(DeltaXZ, vjoy_id, HID_USAGE_SL0)
VJoy_SetAxis(DeltaY, vjoy_id, HID_USAGE_SL1)

return

Edited by magnasaver, 28 July 2020 - 10:23 AM.


#2 magnasaver

magnasaver

    Hobbyist

  • Members
  • PipPip
  • 11 posts

  • Flag: ---------

  • Favorite Pinball: Black Knight

Posted 07 November 2020 - 09:10 AM

Here is some more detailed description of what this script does. It is a quote of a post I made myself in another thread, but since it is directly related to this topic I have decided to post that information here as well.

 


In VPX key settings you can set  your controller axis for nudging. The problem however is, that joystick values are different from accelerometer values and VPX thinks that you are using an accelerometer which gives you weird results.
 
If you move a joystick into one direction, you will get higher values, if you  move your joystick FURTHER into one direction.
If you move an accelermoeter into one direction, you will get higher values, if you move your accelerometer FASTER into one direction.
 
This means as long as you tilt the joystick into one direction, VPX thinks that you continue to move your table into that direction.
If you tilt your joystick furter VPX thinks that you are moving your table faster. But that is not what you want. You usually want that if you are moving your joystick faster VPX should think that you are moving your table faster into that direction.
 
My Autohotkey script (see my previous post) does exactly that and converts the joystick inputs into acceleration values which makes nudging with a joystick  much more realistic. Just give it a try and you will notice the difference.


#3 Cloda

Cloda

    Neophyte

  • Members
  • Pip
  • 4 posts

  • Flag: South Africa

  • Favorite Pinball: Tales from the Crypt

Posted 16 August 2021 - 09:17 PM

I followed the instructions and got everything installed and going etc.  Unfortunately when I start a table, no nudging happens when I use the thumbsticks and it is if the ball is being pulled down by a heavy magnet i.e. it only goes a short way up the plunger lane before dropping down.

I would love to have analogue nudging so would appreciate if you can take a look.
 


YouTube - PinStratsDan


#4 wiesshund

wiesshund

    VPF Legend

  • Members
  • PipPipPipPipPipPipPip
  • 11,859 posts

  • Flag: United States of America

  • Favorite Pinball: How many can i have?

Posted 16 August 2021 - 09:59 PM

I followed the instructions and got everything installed and going etc.  Unfortunately when I start a table, no nudging happens when I use the thumbsticks and it is if the ball is being pulled down by a heavy magnet i.e. it only goes a short way up the plunger lane before dropping down.

I would love to have analogue nudging so would appreciate if you can take a look.
 

 

That is kind of what nudging does
it does not actually drive the ball around

Unless your description isnt exactly how it sounds?


If you feel the need to empty your wallet in my direction, i don't have any way to receive it anyways

Spend it on Hookers and Blow


#5 Wahreez McDermot

Wahreez McDermot

    Enthusiast

  • Members
  • PipPipPip
  • 126 posts
  • Location:Sugar Land, TX

  • Flag: United States of America

  • Favorite Pinball: I can't pick just one!

Posted 25 April 2022 - 07:49 PM

The original DL link is no longer valid as apparently the site was compromised and a RAT was added to the program. There is a new link the site directs you to, but I am not sure if that is the correct version of vJoy or not.

 

The script runs without error, but I achieve no results. I tried connecting my Xbox One controller via USB cable, but that doesn't work either.

 

 

If I open VPX and then use the vjoy feeder program to manually set the slider values I am able to see them take effect in VPX. If I have the script running and then I open the vjoy feeder program it does not show an available device and I can not manipulate the slider values. So the script is running, but it's not having the intended function.

 

When manipulating the sliders using the vJoy feeder program instead of the AHK script it interacts with the table as expected. Setting the sliders both to 50 causes the table to behave normally. Adjusting the sliders above or below causes the ball to move in the expected direction. Unfortunately I can't get it to work with the AHK script.

 

It appears to be an issue with the vjoy_lib.ahk file after looking at the AHK script info.

 

Edit: I ended up just downloading https://github.com/A...croX/antimicrox and using it to bind the keyboard keys to the left stick and nudge that way.


Edited by Wahreez McDermot, 04 June 2022 - 05:47 PM.






Also tagged with one or more of these keywords: xbox controller, gamepad, Autohotkey, nudging