Page 1 of 1

Vjoy Axes Controlled by Keyboard

Posted: Thu Nov 05, 2020 7:49 am
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)

Re: Vjoy Axes Controlled by Keyboard

Posted: Tue Nov 10, 2020 4:19 am
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.

Re: Vjoy Axes Controlled by Keyboard

Posted: Sat Jan 14, 2023 1:45 pm
by gugu2305
muito obrigado me ajudou muito sou brasileiro <3