Mouse to joystick that blends with keyboard input as well

Get help with using AutoHotkey and its commands and hotkeys
Posts: 1
Joined: 14 Sep 2020, 15:53

Mouse to joystick that blends with keyboard input as well

14 Sep 2020, 16:27

Hi, I've been using the same script for many years with ppjoy + glovePIE for use in the X-wing series of games and I really want it to work through the vjoy driver instead so I don't have to worry about leaving my PC in test mode for ppjoy.

I have tried freePIE but I'm not getting the the desired results. You see my glovepie script blends keyboard, mouse and even joystick input together. I have found mouse2joystick_Custom_CEMU.ahk but that doesn't blend the keyboard or joystick movement with mouse.

If anyone with better experience that me can help me bring over the code from my glovePIE script into ahk or has a better way to handle the mouse and keyboard movement it will be appreciated. Most certainly by others too who may want to play the x-wing series with mouse and keyboard as well.

Here is the GlovePIE script I use for x-wing versus tie fighter:

Code: Select all

//Below you put in your mouse dpi setting
pie.MouseDPI = 3200
//this how fast glovepie updates
pie.FrameRate = 60
//This will be the resolution you use in game itself. If you are using the enhance direct 3d
//dll this will be the same as your desktop setting.
var.GameResolutionX = 1920
var.GameResolutionY = 1080
// the screen ratio the game is using needs to be put in here
var.ratiox = 16
var.ratioy = 9
// this will map the range for the mouse input
var.OldMouseX = MapRange(realmouse.DirectInputX, 0,var.GameResolutionX, -1,1)
var.OldMouseY = MapRange(realmouse.DirectInputY, 0,var.GameResolutionY, -1,1)
//this is reading the roll and throttle axis of the first real joystick glovepie finds and assigning it to a var
var.realjoyx = joystick1.roll
var.realjoyy = joystick1.z
//set all the digital movement to 0
var.keyleft = 0
var.keyright = 0
var.keyup = 0
var.keydown = 0
// the update rate which will decide how often to read the mouse and keyboard inputs
wait 0.016 s
// this code updates the new joystick position relative to the last
var.mousex = (var.ratiox*(MapRange(realmouse.DirectInputX, 0,var.GameResolutionX, -1,1) - var.OldMouseX))
var.mousey = (var.ratioy*(MapRange(realmouse.DirectInputY, 0,var.GameResolutionY, -1,1) - var.OldMouseY))

//this code below will work when combined with a joystick axis too, remove the forward slashes to enable
//ppjoy.Analog0 = var.mousex + (var.realjoyx*1.2)
//ppjoy.Analog1 = var.mousey + (var.realjoyy*1.2)

//this assigns the mouse movement to the ppjoy joystick device, known as parallel port joystick 1 in usb controllers control panel of windows
ppjoy.Analog0 = var.mousex
ppjoy.Analog1 = var.mousey

//these pressed and released states will digitally move the joystick combined with the mouse movement for greater precision
if key.down = 1 then
var.keyup = 1
ppjoy.analog1 = var.keyup + var.mousey
end if

if released(key.down) then
var.keyup = 0

ppjoy.analog1 = var.keyup
end if

if key.up = 1 then
var.keydown = -1
ppjoy.analog1 = var.keydown + var.mousey
end if

if released(key.up) then
var.keydown = 0
ppjoy.analog1 = var.keydown
end if

if key.left = 1 then
var.keyleft = -1
ppjoy.analog0 = var.keyleft + var.mousex
end if

if released(key.left) then
var.keyleft = 0
ppjoy.analog0 = var.keyleft
end if

if key.right = 1 then
var.keyright = 1
ppjoy.analog0 = var.keyright + var.mousex
end if

if released(key.right) then
var.keyright = 0
ppjoy.analog0 = var.keyright
end if

//these are just binds of mine showing you can use one key to trigger another, can delete these if you want
if key.end = 1 then
key.w = 1
wait 150 ms
key.w = 0
end if

if key.pagedown = 1 then
key.enter = 1
wait 150 ms
key.enter = 0
end if

if key.pageup = 1 then
key.Space = 1
wait 50 ms = 0
end if

//these are my binds to the mousewheel to use saved power states in game. to save near power states in game, move the mousewheel while pressing shift
//these can be changed to backspace and left bracket keys if you just want the mousewheel to control throttle
if mouse.wheelup then
key.0 = 1
wait 1 ms
key.0 = 0
end if

if mouse.wheeldown then
key.9 = 1
wait 1 ms
key.9 = 0
end if

//these will map ppjoy's joystick button to a 5 button mouse, you can also change the binds of these joystick buttons
//in game
ppjoy.digital0 = mouse.LeftButton
ppjoy.digital1 = mouse.RightButton
ppjoy.digital2 = mouse.MiddleButton
ppjoy.digital3 = mouse.XButton1
ppjoy.digital4 = mouse.XButton2

//Code ends here
Below is my semi successful attempt at using FreePIE:

Code: Select all

from System import Int16
from ctypes import windll, Structure, c_ulong, byref

#Below centers the joystick, read the desktop size and sets the joystick range.

def update():
   global yaw
   global pitch
   global roll
   global lastYaw
   global x
   global y
   global z

if starting:
		vJoy[0].x = 0
		vJoy[0].y = 0
		screen_x = windll.user32.GetSystemMetrics(0)
		screen_y = windll.user32.GetSystemMetrics(1)
		system.threadExecutionInterval = 5
		x = 0
		y = 0
#		joystick[1].setRange(Int16.MinValue, Int16.MaxValue,)

x += mouse.deltaX*200
y += mouse.deltaY*200

if filters.stopWatch(True,50):
	x = 0
	y = 0

vJoy[0].x = x
vJoy[0].y = y

#Below sets the mouse buttons for fire and target infront which uses vjoy joystick buttons 1 and 2.

vJoy[0].setButton(0, mouse.leftButton)
vJoy[0].setButton(1, mouse.rightButton)

#Below is a basic throttle setup for Xvt or XWA. If playing X-wing or Tie fighter then replacing 
#the mouse wheel down bind to the return key works well leaving you to bind the middle mouse button to something else.

if mouse.wheelUp:
if mouse.wheelDown:
if mouse.middleButton:
#Below is keyboard turning speed which gives max turning speed by default
if keyboard.getKeyDown(Key.UpArrow):
	vJoy[0].y = -Int16.MaxValue + (mouse.deltaY*500)
if keyboard.getKeyDown(Key.DownArrow):
	vJoy[0].y = Int16.MaxValue + (mouse.deltaY*500)

if keyboard.getKeyDown(Key.LeftArrow):
	vJoy[0].x = -Int16.MaxValue + (mouse.deltaX*500)
if keyboard.getKeyDown(Key.RightArrow):
	vJoy[0].x = Int16.MaxValue + (mouse.deltaX*500)
# This is just a readout for the watch tab below[0].x)[0].y)[1].z)[1].zRotation)[1].x)[1].y)

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], mouseman82 and 37 guests