Mouse to vJoy script

Official forum for open source FreePIE discussion and development.
Post Reply
fern
One Eyed Hopeful
Posts: 3
Joined: Sat Feb 15, 2014 11:49 pm

Mouse to vJoy script

Post by fern »

First, thank you for creating this software. I used GlobePIE with PPjoy, that is no longer supported, and I'm glad to find there are open source versions, FreePIE and vJoy, that work under windows 8.

I wrote this script to control a driving game with my mouse:
- Horizontal mouse controls the steer (middle mouse for auto-center).
- Downward Vertical mouse, while holding right button, controls the gas.
- Upward Vertical mouse, while holding left button, controls the brake.

Code: Select all

from System import Int16

if starting:
   x = 0
   y = 0
   z = 0
   sensibilidadX = 50
   sensibilidadY = 100
   sensibilidadZ = 100

x += mouse.deltaX * sensibilidadX

if mouse.middleButton:
   x = 0

if mouse.rightButton:
   y += mouse.deltaY * sensibilidadY
else:
   y = 0

if mouse.leftButton:
   z -= mouse.deltaY * sensibilidadZ
else:
   z = 0

if (x > Int16.MaxValue):
   x = Int16.MaxValue
elif (x < -Int16.MaxValue):
   x = -Int16.MaxValue

if (y > Int16.MaxValue):
   y = Int16.MaxValue
elif (y < 0):
   y = 0

if (z > Int16.MaxValue):
   z = Int16.MaxValue
elif (z < 0):
   z = 0
   
vJoy[0].x = x
vJoy[0].y = y
vJoy[0].z = z

diagnostics.watch(vJoy[0].x)
diagnostics.watch(vJoy[0].y)
diagnostics.watch(vJoy[0].z)
I'm only missing the use of mouse wheel up/down to shift the gear.
Is it possible with freePIE (or it is planned) to asign the mouse wheel? or the 4th and 5th mouse buttons?
Thanks
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Mouse to vJoy script

Post by CyberVillain »

You can get any button with mouse.getButton(x)

where x is the number of the button

Mouse whee is not supported at the moment, can look into it when I get time
CyberVillain
Petrif-Eyed
Posts: 2166
Joined: Mon Jun 22, 2009 8:36 am
Location: Stockholm, Sweden

Re: Mouse to vJoy script

Post by CyberVillain »

Added mouse wheel support, will be in next release
fern
One Eyed Hopeful
Posts: 3
Joined: Sat Feb 15, 2014 11:49 pm

Re: Mouse to vJoy script

Post by fern »

Great!
Thank you very much CyberVillain.
MGraf
One Eyed Hopeful
Posts: 1
Joined: Fri May 23, 2014 7:54 am

Re: Mouse to vJoy script

Post by MGraf »

great script. very useful for diseased peopels like me.

but i have the feel, there is a small deadzone. is this possible?

greets michi
samworthington
One Eyed Hopeful
Posts: 12
Joined: Tue Jun 16, 2015 4:49 am

Re: Mouse to vJoy script

Post by samworthington »

Thanks for this. Even with my fumbling I've managed to update it so it's more suitable for flight sims with the left and right mouse movements translating to joystick pitch and roll and the middle button just zeroing it.

Sam

from System import Int16

if starting:
x = 0
y = 0
z = 0
sensibilidadX = 30
sensibilidadY = 30
sensibilidadZ = 100

x += mouse.deltaX * sensibilidadX
y += mouse.deltaY * sensibilidadY

if mouse.middleButton:
x = 0
y = 0


if mouse.leftButton:
z -= mouse.deltaY * sensibilidadZ
else:
z = 0

if (x > Int16.MaxValue):
x = Int16.MaxValue
elif (x < -Int16.MaxValue):
x = -Int16.MaxValue

if (y > Int16.MaxValue):
y = Int16.MaxValue
elif (y < -Int16.MaxValue):
x = -Int16.MaxValue

if (z > Int16.MaxValue):
z = Int16.MaxValue
elif (z < 0):
z = 0

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

diagnostics.watch(vJoy[0].x)
diagnostics.watch(vJoy[0].y)
diagnostics.watch(vJoy[0].z)
samworthington
One Eyed Hopeful
Posts: 12
Joined: Tue Jun 16, 2015 4:49 am

Re: Mouse to vJoy script

Post by samworthington »

I'm trying to modify so when the joystick function only works when I press the right mouse button. I've tried the following but it doesn't work properly so any suggestions would be appreciated.

Lines 11 and 12 changed as follows:
x += (mouse.deltaX + mouse.rightButton) * sensibilidadX
y += (mouse.deltaY + mouse.rightButton) * sensibilidadY

Sam


from System import Int16

if starting:
x = 0
y = 0
z = 0
sensibilidadX = 30
sensibilidadY = 30
sensibilidadZ = 100

x += (mouse.deltaX + mouse.rightButton) * sensibilidadX
y += (mouse.deltaY + mouse.rightButton) * sensibilidadY

if mouse.middleButton:
x = 0
y = 0


if mouse.leftButton:
z -= mouse.deltaY * sensibilidadZ
else:
z = 0

if (x > Int16.MaxValue):
x = Int16.MaxValue
elif (x < -Int16.MaxValue):
x = -Int16.MaxValue

if (y > Int16.MaxValue):
y = Int16.MaxValue
elif (y < -Int16.MaxValue):
x = -Int16.MaxValue

if (z > Int16.MaxValue):
z = Int16.MaxValue
elif (z < 0):
z = 0

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

diagnostics.watch(vJoy[0].x)
diagnostics.watch(vJoy[0].y)
diagnostics.watch(vJoy[0].z)
FrenchyKiel
One Eyed Hopeful
Posts: 47
Joined: Thu Oct 03, 2013 7:10 am

Re: Mouse to vJoy script

Post by FrenchyKiel »

i dont understand why you write:

x += (mouse.deltaX + mouse.rightButton) * sensibilidadX
y += (mouse.deltaY + mouse.rightButton) * sensibilidadY

you are adding a double value and a boolean value?

the original lines were correct for me (without the mouse.rightbutton)

second problem the voy axis value are limited to + and -16382

so dont limit the value to int16 max value (32767) but by vJoy[0].axisMax value

so the new code is

Code: Select all

if starting:
	x = 0
	y = 0
	z = 0
	sensibilidadX = 30
	sensibilidadY = 30
	sensibilidadZ = 100
	MaxValue = vJoy[0].axisMax

x += (mouse.deltaX) * sensibilidadX
y += (mouse.deltaY) * sensibilidadY



if mouse.middleButton:
	x = 0
	y = 0


if mouse.leftButton:
	z -= mouse.deltaY * sensibilidadZ
else:
	z = 0

if (x > MaxValue):
	x = MaxValue
elif (x < -MaxValue):
	x = -MaxValue

if (y > MaxValue):
	y = MaxValue
elif (y < -MaxValue):
	x = -MaxValue

if (z > MaxValue):
	z = MaxValue
elif (z < 0):
	z = 0

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

diagnostics.watch(vJoy[0].x)
diagnostics.watch(vJoy[0].y)
diagnostics.watch(vJoy[0].z)
samworthington
One Eyed Hopeful
Posts: 12
Joined: Tue Jun 16, 2015 4:49 am

Re: Mouse to vJoy script

Post by samworthington »

I'm totally new to FreePIE and to programming in general so please excuse my lack of understanding.

I wrote the + mouse.rightButton bit to try and get the joystick function to only work when I press the right mouse button.
Post Reply

Return to “FreePIE”