At first glance I thought this was the same use case which prompted my PWM-analog-faking script (to fake graduated command through binary control inputs), but after reading through it, this is in fact the exact opposite scenario. You have an analog destination control which you want to actuate via variable duration taps of a binary source input....
This is something which is much easier handled from the game side, but alas, not all games implement control lerping the same, and some do it better than others.
The good news is that there is a FreePIE solution, using VJoy and a script to lerp its axes based on keys:
Code: Select all
Pseudocode (more or less):
# linear interpolation
def Lerp(v0, v1, t):
return (v1 - v0) * t + v0
if (starting):
global sharpness
sharpness = 8
global tLast
tLast = 0
#main script loop:
deltaTime = (time.clock() - tLast)
tLast = time.clock()
# control the X axis using the A and D keys
tgtX = 0
if (keyboard.getKey(A)):
tgtX = tgtX - 1
if (keyboard.getKey(D)):
tgtX = tgtX + 1
vJoy[0].x = Lerp(vJoy[0].x, tgtX, sharpness * deltaTime)
# that takes care of the X axis using A and D, you'd do the same with other keys and other axes.
Multiplying 'sharpness' with the time delta between each tick of the script means the lerping rate becomes independent of the execution rate of the script itself, so it doesn't matter that much how fast it runs. The axes are always interpolating between their current position and a given 'target' position. The keys you press just set the target, and because each key just increments the target either one way or another, pressing both at the same time will cancel out at zero.
Lastly, I haven't tested this code at all... I'm not sure if it's even good python syntax as it is, but the idea behind it I know will work. This is (essentially) how keyboard controls are processed in KSP.
Hope this helps!
Cheers