Vjoy Axes Controlled by Keyboard

Official forum for open source FreePIE discussion and development.
Post Reply
nevs
One Eyed Hopeful
Posts: 1
Joined: Thu Nov 05, 2020 7:42 am

Vjoy Axes Controlled by Keyboard

Post by nevs »

Hi,

I am looking to control the Z axis of a Vjoy joystick so that if I press Num 0, the axes moves down and if I press Num Enter it moves up, but incrementally.

I also dont want it to auto center.

I can make a script to make this happen, but not on an incremental basis, just either full min/max.

I need it to act that when I hold down they key, it keeps gradually increasing the value on the axes....

My script so far is:

from System import Int16

# Devices and axis initializing
max = Int16.MaxValue*0.5+0.5 # 16384
min = -Int16.MaxValue*0.5-0.5 # -16384
joystick[0].setRange(min, max)
joyZ = 0

##### Axis fallback, for easy assignment

# Joystick Axis
if keyboard.getKeyDown(Key.NumberPad0):
vJoy[0].z = min
if keyboard.getKeyDown(Key.NumberPadEnter):
vJoy[0].z = max

# vJoy
diagnostics.watch(vJoy[0].z)
Jabberwock
Cross Eyed!
Posts: 197
Joined: Mon Mar 02, 2015 3:58 pm

Re: Vjoy Axes Controlled by Keyboard

Post by Jabberwock »

Two simple ones:

This one sets one increase per press.

Code: Select all

if vJoy[0].z < vJoy[0].axisMax and keyboard.getPressed(Key.NumberPad0):
	vJoy[0].z = vJoy[0].z + vJoy[0].axisMax / 10
if vJoy[0].z > -vJoy[0].axisMax and keyboard.getPressed(Key.NumberPadEnter):
	vJoy[0].z = vJoy[0].z - vJoy[0].axisMax / 10
diagnostics.watch(vJoy[0].z)
This one is continous, but slow. Of course, you can increase the step.

Code: Select all

if vJoy[0].z < vJoy[0].axisMax and keyboard.getKeyDown(Key.NumberPad0):
	vJoy[0].z = vJoy[0].z + 50 
if vJoy[0].z > -vJoy[0].axisMax and keyboard.getKeyDown(Key.NumberPadEnter):
	vJoy[0].z = vJoy[0].z - 50 
diagnostics.watch(vJoy[0].z)
Note that at the min/max values they overshoot the value a bit, but vjoy does not seem to mind. With larger steps you might want to limit the value not to axisMax, but to the last step taken.
gugu2305
One Eyed Hopeful
Posts: 1
Joined: Sat Jan 14, 2023 1:43 pm

Re: Vjoy Axes Controlled by Keyboard

Post by gugu2305 »

muito obrigado me ajudou muito sou brasileiro <3
Post Reply

Return to “FreePIE”