I use X/Y for both steering, acceleration and breaking. The Z axis is reserved for the clutch which works perfectly fine but it would be much more convenient to have a button as well so I don't always have to use the scroll for clutch, but I can only press a button (this will happen when the vehicle gains some speed already).
So the button is Tab and should be a bit smooth. Do you guys have any idea how to do this? My code is edited from Joyness, and it's a bit messy... Still, can anyone help me out?
Code: Select all
#Title :OMSI 2 Freepie Mouse (Edited Mjoy vJoy FreePIE python script)
#Version :0.1 (2016-03-22)
#Author :snp, NEMOROSUS
#Description :FreePIE python script for OMSI 2 mouse controls such as acceleration, steering and clutch control that is more accurate that the built-in one.
import time
from System import Int16
from ctypes import windll, Structure, c_ulong, byref
class POINT(Structure):
_fields_ = [("x", c_ulong), ("y", c_ulong)]
if starting:
vJoy0_stat = 1
vJoy[0].x = 0
vJoy[0].y = 0
vJoy[0].z = 0
vJoy[0].rx = 0
x = 0
y = 0
z = 0
rx = 0
mouse_x = 0
mouse_y = 0
mouse_z = 0
mouse_x_locked = 0
mouse_y_locked = 0
x_m = 0
y_m = 0
z_m = 0
axis_max = 16448
screen_x = windll.user32.GetSystemMetrics(0)
screen_y = windll.user32.GetSystemMetrics(1)
pt = POINT()
sequence = 0
system.setThreadTiming(TimingTypes.HighresSystemTimer)
system.threadExecutionInterval = 1
z += mouse.wheel * 20
if keyboard.getPressed(Key.Tab):
rx = 1
# X/Y axis centering
if keyboard.getKeyDown(Key.Space):
windll.user32.SetCursorPos((screen_x / 2),(screen_y / 2))
# Clutch for gears in speed
# Turn script on/off
if keyboard.getPressed(Key.K):
if sequence == 0:
vJoy0_stat = 0
elif sequence == 1:
vJoy0_stat = 1
sequence = sequence + 1
if sequence > 1:
sequence = 0
if vJoy0_stat == 1:
windll.user32.GetCursorPos(byref(pt))
mouse_x = pt.x
mouse_y = pt.y
sensitivity = 32
x_m = (mouse_x - (screen_x / 2)) * sensitivity
y_m = (mouse_y - (screen_y / 2)) * sensitivity
x_both = x_m + x
y_both = y_m + y
x_keyb_sensitivity = 350
y_keyb_sensitivity = 350
if x_m > axis_max:
x_m = axis_max
if x_m < - axis_max:
x_m = - axis_max
if y_m > axis_max:
y_m = axis_max
if y_m < - axis_max:
y_m = - axis_max
if x > axis_max:
x = axis_max
if x < - axis_max:
x = - axis_max
if y > axis_max:
y = axis_max
if y < - axis_max:
y = - axis_max
if z > axis_max:
z = axis_max
if z < - axis_max:
z = - axis_max
if rx > axis_max:
rx = axis_max
if rx < - axis_max:
rx = - axis_max
if x_both > axis_max:
x_both = axis_max
if x_both < - axis_max:
x_both = - axis_max
if y_both > axis_max:
y_both = axis_max
if y_both < - axis_max:
y_both = - axis_max
vJoy[0].x = x_m + x
vJoy[0].y = y_m + y
vJoy[0].z = z_m + z
vJoy[0].rx = z
# Diag
diagnostics.watch(screen_x)
diagnostics.watch(screen_y)
diagnostics.watch(mouse_x)
diagnostics.watch(mouse_y)
diagnostics.watch(mouse_x_locked)
diagnostics.watch(mouse_y_locked)
diagnostics.watch(vJoy[0].x)
diagnostics.watch(vJoy[0].y)
diagnostics.watch(vJoy[0].z)
diagnostics.watch(vJoy[0].rx)