It emulates analog gas and brake pedals by using the vertical movement of the mouse, but only when a mouse button is pressed:
- Accelerate: Press the right mouse button and move the mouse down.
- Brake: Press the left mouse button and move the mouse up.
I suggest to set the game to use linear steering, with no smoothing filters, nor deadbands.
The keys Q, A, Z, X, and the 4th and 5th mouse buttons, are set to emulate joy buttons. The mouse wheel is also configured to trigger a joy button click. I use it to shift gear, so I can drive the car with one single hand.
In netkar, when I drive a F1 car that has 400º of max steering range, the sensibility of the controller remains the same, but the rest of the mouse/wheel movement range (up to 900º) is ignored. I set the value "carLockToLockSteering" to 400 in this case (similar to the steeringLock value available for some wheel controllers).
I hope someone else finds it useful, or as a starting point for your own scripts.
Code: Select all
if starting:
autoCenterSpeed = 0.1 # Auto center speed when middle mouse button pressed
maxLockToLockSteering = 900 # Max steering lock in game
carLockToLockSteering = 900 # Limits the range of the wheel, while keeping the same sensibility
sensX = 3 # Steering sensibility (Horizontal).
sensY = 60 # Gas sensibility (Vertical down)
sensZ = 60 # Brake sensibility (Vertical up)
joy=vJoy[14]
xMax = joy.axisMax
yMax = joy.axisMax
zMax = joy.axisMax
# Steering lock
if (carLockToLockSteering < maxLockToLockSteering):
xMax = xMax * carLockToLockSteering / maxLockToLockSteering
x = 0
y = 0
z = 0
wheelUp = 0
wheelDown = 0
# Steering with mouse left-right
x += mouse.deltaX * sensX
# Autocenter (while middle button pressed)
if mouse.middleButton:
x /= (1 + autoCenterSpeed)
# Accelerate with mouse down (while right button pressed)
if mouse.rightButton:
y += mouse.deltaY * sensY
else:
y = 0
# Brake with mouse up (while left button pressed)
if mouse.leftButton:
z -= mouse.deltaY * sensZ
else:
z = 0
# Max ranges
if (x > xMax):
x = xMax
elif (x < -xMax):
x = -xMax
if (y > yMax):
y = yMax
elif (y < 0):
y = 0
if (z > zMax):
z = zMax
elif (z < 0):
z = 0
# Joy axis
joy.x = x
joy.y = y
joy.z = z
# Joy buttons
joy.setButton(0, keyboard.getKeyDown(Key.Q))
joy.setButton(1, keyboard.getKeyDown(Key.A))
joy.setButton(2, keyboard.getKeyDown(Key.Z))
joy.setButton(3, keyboard.getKeyDown(Key.X))
joy.setButton(4, mouse.getButton(3))
joy.setButton(5, mouse.getButton(4))
if mouse.wheelDown:
wheelDown = 10
if wheelDown > 0:
wheelDown -= 1
joy.setButton(6,True)
else:
joy.setButton(6,False)
if mouse.wheelUp:
wheelUp = 10
if wheelUp > 0:
wheelUp -= 1
joy.setButton(7,True)
else:
joy.setButton(7,False)
diagnostics.watch(joy.x)
diagnostics.watch(joy.y)
diagnostics.watch(joy.z)