The online racing simulator
Can you make me a mouse steering script where the steering depends on the mouse position on screen? Like if my mouse is on the edge of my screen, it will be max steering and when its in the middle, then its = 0. And put an auto center if you don't mind.
It's that exactly how mouse steering works...?
Hello, I want to have mouse buttons as accelerator and brake. I tried to modify an already modified (more simpler) version of Skagen's script but, apparently, I'm doing it wrong.
I changed throttle and brake binds to ''mouse.leftButton'' and ''mouse.rightButton'' respectively, but because of that, I get error ''line 104 expected Key, got bool''
Anyone know how I can solve this? I'm too used to having throttle and brakes with mouse buttons to change now.
Here is the code I currently have.
# =============================================================================================
# /////////////////////////////// F1 2014 Mouse Steering Script ///////////////////////////////
# =============================================================================================
# This is a modified script, the original script was written by Skagen
# url: https://www.lfs.net/forum/post/1862759#post1862759
# =============================================================================================
# This script will use 3 axes
# 1. Steering (X-Axis)
# 2. Throttle (Y-Axis)
# 3. Brake (Z-Axis)
# =============================================================================================
# Use vJoy Feeder to set the axes in game
# =============================================================================================
if starting:
system.setThreadTiming(TimingTypes.HighresSystemTimer)
system.threadExecutionInterval = 5
def calculate_rate(max, time):
if time > 0:
return max / (time / system.threadExecutionInterval)
else:
return max

int32_max = (2 ** 14) - 1
int32_min = (( 2** 14) * -1) + 1

v = vJoy[0]
v.x, v.y, v.z, v.rx, v.ry, v.rz, v.slider, v.dial = (int32_min,) * 8
# =============================================================================================
# //////////////////////////////////////// SETTINGS ///////////////////////////////////////////
# =============================================================================================
# Mouse settings
# =============================================================================================
# Higher SCR = Smoother/Slower Response | Lower SCR = Harder/Quicker Response
# With the game's built in steering settings, there's no need to change the scr value
# SCR's effects can be felt better with arcade style racing games
# =============================================================================================
global mouse_sensitivity, sensitivity_center_reduction
mouse_sensitivity = 7
sensitivity_center_reduction = 0.8
# =============================================================================================
# Throttle & Brake Key:
# =============================================================================================
global throttle_key, brake_key
throttle_key = mouse.leftButton
brake_key = mouse.rightButton
# Additional controls: Wheel Up = Reset Steering to Center @ Line 89
# =============================================================================================
# Throttle settings
# =============================================================================================
# Set throttle behaviour with the increase and decrease time (ms)
# the actual increase and decrease rates are calculated automatically
throttle_increase_time = 600
throttle_decrease_time = 600
# Init values, do not change
global throttle, throttle_max, throttle_min, throttle_increase_rate, throttle_decrease_rate
throttle_max = int32_max
throttle_min = int32_min
throttle = throttle_min
throttle_increase_rate = calculate_rate(throttle_max, throttle_increase_time)
throttle_decrease_rate = calculate_rate(throttle_max, throttle_decrease_time) * -1
# =============================================================================================
# Braking settings
# =============================================================================================
# Set brake behaviour with the increase and decrease time (ms)
# the actual increase and decrease rates are calculated automatically
braking_increase_time = 200
braking_decrease_time = 100
# Init values, do not change
global braking, braking_max, braking_min, braking_increase_rate, braking_decrease_rate
braking_max = int32_max
braking_min = int32_min
braking = braking_min
braking_increase_rate = calculate_rate(braking_max, braking_increase_time)
braking_decrease_rate = calculate_rate(braking_max, braking_decrease_time) * -1
# =============================================================================================
# Steering settings
# =============================================================================================
global steering, steering_max, steering_min, steering_center_reduction
# Init values, do not change
steering = 0.0
steering_max = float(int32_max)
steering_min = float(int32_min)
steering_center_reduction = 1.0
# =================================================================================================
# LOOP START
# =================================================================================================
# Steering logic
# =================================================================================================
if mouse.wheelUp:
steering = 0.0
if steering > 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_max))
elif steering < 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_min))
steering = steering + ((float(mouse.deltaX) * mouse_sensitivity) / steering_center_reduction)
if steering > steering_max:
steering = steering_max
elif steering < steering_min:
steering = steering_min
v.x = int(round(steering))
# =================================================================================================
# Throttle logic
# =================================================================================================
if keyboard.getKeyDown(throttle_key):
throttle = throttle + throttle_increase_rate
else:
throttle = throttle + throttle_decrease_rate
if throttle > throttle_max:
throttle = throttle_max
elif throttle < throttle_min:
throttle = throttle_min
v.y = throttle
# =================================================================================================
# Braking logic
# =================================================================================================
if keyboard.getKeyDown(brake_key):
braking = braking + braking_increase_rate
else:
braking = braking + braking_decrease_rate
if braking > braking_max:
braking = braking_max
elif braking < braking_min:
braking = braking_min
v.z = braking
# =================================================================================================
# vJoy BUTTONS
# F1 2014 allows keyboard controls mixed with other input devices, so we don't need to set any more
# =================================================================================================
v.setButton(0,int(mouse.leftButton))
v.setButton(1,int(mouse.rightButton))
v.setButton(2,int(mouse.middleButton))
# =================================================================================================
# PIE diagnostics logic
# =================================================================================================
diagnostics.watch(v.x)
diagnostics.watch(v.y)
diagnostics.watch(v.z)
diagnostics.watch(steering_center_reduction)

Just use "if throttle_key:".
Thanks, now the error is gone, but the mouse buttons don't do anything.
I have another problem : I binded vJoy buttons to my keyboard but on the monitor they are pressed even when I'm not touching them. Here is my updated code.
# =============================================================================================
# /////////////////////////////// F1 2014 Mouse Steering Script ///////////////////////////////
# =============================================================================================
# This is a modified script, the original script was written by Skagen
# url: https://www.lfs.net/forum/post/1862759#post1862759
# =============================================================================================
# This script will use 3 axes
# 1. Steering (X-Axis)
# 2. Throttle (Y-Axis)
# 3. Brake (Z-Axis)
# =============================================================================================
# Use vJoy Feeder to set the axes in game
# =============================================================================================
if starting:
system.setThreadTiming(TimingTypes.HighresSystemTimer)
system.threadExecutionInterval = 5
def calculate_rate(max, time):
if time > 0:
return max / (time / system.threadExecutionInterval)
else:
return max

int32_max = (2 ** 14) - 1
int32_min = (( 2** 14) * -1) + 1

v = vJoy[0]
v.x, v.y, v.z, v.rx, v.ry, v.rz, v.slider, v.dial = (int32_min,) * 8
# =============================================================================================
# //////////////////////////////////////// SETTINGS ///////////////////////////////////////////
# =============================================================================================
# Mouse settings
# =============================================================================================
# Higher SCR = Smoother/Slower Response | Lower SCR = Harder/Quicker Response
# With the game's built in steering settings, there's no need to change the scr value
# SCR's effects can be felt better with arcade style racing games
# =============================================================================================
global mouse_sensitivity, sensitivity_center_reduction
mouse_sensitivity = 11
sensitivity_center_reduction = 1
# =============================================================================================
# Throttle & Brake Key:
# =============================================================================================
global throttle_key, brake_key
throttle_key = mouse.leftButton
brake_key = mouse.rightButton
# Additional controls: Wheel Up = Reset Steering to Center @ Line 89
# =============================================================================================
# Throttle settings
# =============================================================================================
# Set throttle behaviour with the increase and decrease time (ms)
# the actual increase and decrease rates are calculated automatically
throttle_increase_time = 140
throttle_decrease_time = 220
# Init values, do not change
global throttle, throttle_max, throttle_min, throttle_increase_rate, throttle_decrease_rate
throttle_max = int32_max
throttle_min = int32_min
throttle = throttle_min
throttle_increase_rate = calculate_rate(throttle_max, throttle_increase_time)
throttle_decrease_rate = calculate_rate(throttle_max, throttle_decrease_time) * -1
# =============================================================================================
# Braking settings
# =============================================================================================
# Set brake behaviour with the increase and decrease time (ms)
# the actual increase and decrease rates are calculated automatically
braking_increase_time = 140
braking_decrease_time = 220
# Init values, do not change
global braking, braking_max, braking_min, braking_increase_rate, braking_decrease_rate
braking_max = int32_max
braking_min = int32_min
braking = braking_min
braking_increase_rate = calculate_rate(braking_max, braking_increase_time)
braking_decrease_rate = calculate_rate(braking_max, braking_decrease_time) * -1
# =============================================================================================
# Steering settings
# =============================================================================================
global steering, steering_max, steering_min, steering_center_reduction
# Init values, do not change
steering = 0.0
steering_max = float(int32_max)
steering_min = float(int32_min)
steering_center_reduction = 1
# =================================================================================================
# LOOP START
# =================================================================================================
# Steering logic
# =================================================================================================
if mouse.wheelUp:
steering = 0.0
if steering > 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_max))
elif steering < 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_min))
steering = steering + ((float(mouse.deltaX) * mouse_sensitivity) / steering_center_reduction)
if steering > steering_max:
steering = steering_max
elif steering < steering_min:
steering = steering_min
v.x = int(round(steering))
# =================================================================================================
# Throttle logic
# =================================================================================================
if throttle_key:
throttle = throttle + throttle_increase_rate
else:
throttle = throttle + throttle_decrease_rate
if throttle > throttle_max:
throttle = throttle_max
elif throttle < throttle_min:
throttle = throttle_min
v.y = throttle
# =================================================================================================
# Braking logic
# =================================================================================================
if brake_key:
braking = braking + braking_increase_rate
else:
braking = braking + braking_decrease_rate
if braking > braking_max:
braking = braking_max
elif braking < braking_min:
braking = braking_min
v.z = braking
# =================================================================================================
# vJoy BUTTONS
# F1 2014 allows keyboard controls mixed with other input devices, so we don't need to set any more
# =================================================================================================
v.setButton(0,int(mouse.middleButton))
v.setButton(1,int(Key.A))
v.setButton(2,int(Key.Z))
v.setButton(3,int(Key.C))
v.setButton(4,int(Key.X))
v.setButton(5,int(Key.S))
v.setButton(6,int(Key.D))
v.setButton(7,int(Key.Q))
# =================================================================================================
# PIE diagnostics logic
# =================================================================================================
diagnostics.watch(v.x)
diagnostics.watch(v.y)
diagnostics.watch(v.z)
diagnostics.watch(steering_center_reduction)

What I'm doing wrong? Thanks
I solved my problems now. Thanks for helping.
Hello, thank for all those script,it help a lot Big grin i have a problem with Iracing using vJoy and freepie. When calibrate, the game understand the input of the key and not the virtual axis.

I quote the devs: "I think the reason you can't get your code to work is because vjoy is not hiding the 'f' key from us when you push it during calibration. So we are recieving the 'f' key, followed by an axis move message from vjoy. The problem is that we favor key presses over joystick moves, and so we are picking up on the 'f' key and not the axis. Of course it is also possible that the script is just not working correctly.

You can probably work around this by adding in yet another key press, or a calibration mode to your script, where a single press of 'f' causes the throttle axis to slowly go from 0 to 100% and back to 0 4-5 times in a row (say over 5 seconds). That will give our code time to pick up on the moving axis during calibration so we can forget about the 'f' key being sent to us. If you can make it past the calibration step then we can handle the rest just fine.
"
Anyone could help me writing such a code for calibrate or to hide the key input with a function? any help would be appreciate much, thanks Wink
You may use the feeder demo app to get around this, then switch back to your script. Alternatively, config your script to use a key iR refuses to recognize.
I just keep the key holded from desktop to game, so the game didnt get the first input and recognized the axis, thank for replying anyway Wink
Now i'm playing with a Xbox controler+mouse,
So my question is: how the trigger of the xbox controler can be activate partialy by freepie, cant find value to input in the code.
Registered just to say thanks to all of you guys for these scripts! Had zero knowledge of any of this just couple hours ago and now i'm up and running in euro truck simulator 1 (yes, that's my cup of tea Big grin) with full mouse control.
Special thanks to Skagen, apparently it's his script that the guy on youtube had modified (with credit to here) and used to show how vjoy, freepie and the script(s) make all this work. Thanks for doing all this programming tinkering so i can just drive Big grin Cheers!
Quote from biboul :Now i'm playing with a Xbox controler+mouse,
So my question is: how the trigger of the xbox controler can be activate partialy by freepie, cant find value to input in the code.

Somehow missed your post before.

Look for the boundary values used for axis output, usual something defined as int32_min/max. For example in bouba's post above the steering control has:
if steering > steering_max:
steering = steering_max
elif steering < steering_min:
steering = steering_min

And those boundary values are defined as:
int32_max = (2 ** 14) - 1
int32_min = (( 2** 14) * -1) + 1
...
steering_max = float(int32_max)
steering_min = float(int32_min)

The int32_min/max values are the minimum/maximum of what the system will recognize, which is full activation. If you want partial activation, you would need to reduce the absolute value of those boundaries. If you change it like this:
steering_max = float(int32_max) * 0.5
steering_min = float(int32_min) * 0.5

You would steer only half way to the left/right at most.
Hello mates.

I saw this video: https://www.youtube.com/watch?v=Q3r3e9NcaFc and had an idea. By the way, the video is about making a wheel by having the wheel column (cylinder) rotate around a fixed mouse's x axis. Mouse buttons are used for throttle and brake pedals.

The idea I had was to use 3 (or 4) mice. One for steering (x axis), one for throttle (Y+), one for brake (Y-) and one more, possibly, for shifting using the mouse wheel.

I can envision a setup where the mouse is pushed forward (from point A to B on a fixed surface) on depressing a home made throttle peddle contraption. But, the mouse would need to come back to its original position when lifting the throttle. This would engage the Y- axis, unless the particular mouse used for throttle could be operated by a script. It is impracticable to have the mouse move forward continuously every time the throttle is depressed and released, without making the mouse come back. The mouse assigned for throttle will have to travel to another country lol, given how much we'd have to depress, release the throttle pedal.

The same thing follows for the brake pedal. It would have to be pushed back on depressing the brake pedal, and come back to its original position when lifted. A mechanical setup can be envisaged for this also. But, again, the same issue of Y+ being engaged when the brake-mouse comes back to its original position would have to be dealt with. I don't anything about python, so I don't know if dead zones can be defined with actual coordinates of the mice being used.

Before the use of another mouse can be even thought of, I'd like to know if vJoy and GlovePie can be configured to register each mouse (and its axes and buttons) as inputs of a larger controller, instead of being read as mouse by the computer. If a driver needs to be written to have all mice understood as a single controller, it's game over (at least for me on Win 8.1).

So, ppl, can this be done with vJoy and GlovePie?
Assuming this can be done, use and setup of springs can mimic some sensation of steering and pedal sensitivities.
Yes.

However, I'm quite sure modding a gamepad for pedals/handbrake is easier, even if the software side of things are working for you. With the mouse approach you'll also need some really good mouse sensors and aggressive re-calibration to suppress drift.


BTW, Bogdan '94 doesn't really like his fingers. Taped Shut
Hello. Someone can help me and edit this functions in script ?


from ctypes import *
user32 = windll.user32

if starting:
# feature toggle
vjoyaxis = True
assists = False # auto throttle cut off & blip
mouselock = False # locking mouse position for assetto corsa
debouncing = True # prevent double shifting, set False to disable
# assign vjoy device number
v = vJoy[0]
# vjoy axis range, do not modify
a_max = 1 + v.axisMax
a_min = -1 - v.axisMax
# mouse steering
m_sens = 16.0 # mouse sensitivity (higher faster)
m_redu = 4 # center reduction sensitivity, acceptable range 1-50, set to 1 to disable
steering = 0 # do not modify
center_redu = 1 # center reduction; init value, do not modify
# throttle
th_axis = a_min
th_inc = 240 # increase speed (higher faster)
th_dec = 300 # decrease speed
th_max = a_max # for throttle limit
# brake
br_axis = a_min
br_inc = 240
br_dec = 300
br_max = a_max # for brake limit
# handbrake
ha_axis = a_min
ha_inc = 300
ha_dec = 600
# clutch
cl_axis = a_min
cl_inc = 2000
cl_dec = 600
# auto blip
blip_m = 0.4 # amount throttle applied on blip; range 0.0-1.0; 0.0=0% throttle, 1.0=100%
a_blip = a_max * 2 * blip_m - a_max # calculation, do not modify
# debouncing
stimer = 0 # shifting timer
t_upshift = 140 # minimum time required for next gear
# throttle limit
tlimit = 0.9 # throttle limited at 90%; range 0.0-1.0; useful for cars without traction control under low gears
th_limit = a_max * 2 * tlimit - a_max # calculation, do not modify

#======== assign key here ========#
# toggle
toggle_vjoyaxis = keyboard.getPressed(Key.Grave) # axis calculation
toggle_mouselock = mouse.getPressed(2) # mouselock
key_assists_on = keyboard.getKeyDown(Key.NumberPad1) or mouse.wheelUp
key_assists_off = keyboard.getKeyDown(Key.NumberPad3) or mouse.wheelDown
# vehicle control
key_throttle = keyboard.getKeyDown(Key.W)
key_brake = keyboard.getKeyDown(Key.S)
key_handbrake = keyboard.getKeyDown(Key.V)
key_clutch = keyboard.getKeyDown(Key.C)
key_centerx = mouse.getButton(2) # center steering (x-axis)
key_shiftup = keyboard.getPressed(Key.L)
key_shiftdown = keyboard.getPressed(Key.K)
# brake limit
bl_70 = keyboard.getPressed(Key.NumberPad7)
bl_75 = keyboard.getPressed(Key.NumberPad4)
bl_80 = keyboard.getPressed(Key.NumberPad8)
bl_85 = keyboard.getPressed(Key.NumberPad5)
bl_90 = keyboard.getPressed(Key.NumberPad9)
bl_95 = keyboard.getPressed(Key.NumberPad6)
no_bl = keyboard.getPressed(Key.NumberPadPeriod)
# throttle limit
key_throttle_limit = mouse.getButton(0) # throttle limit is only applied while holding down assign key

#======== toggle ========#
if toggle_vjoyaxis:
vjoyaxis = not vjoyaxis
if toggle_mouselock:
mouselock = not mouselock
if key_assists_on:
assists = True
if key_assists_off:
assists = False

#======== mouselock ========#
if (mouselock):
user32.SetCursorPos(0 , 5000) # pixel coordinates (x, y)

#======== axis calculation ========#
if (vjoyaxis):
# mouse steering
if steering > 0:
center_redu = m_redu ** (1 - (steering / a_max))
elif steering < 0:
center_redu = m_redu ** (1 - (steering / a_min))
steering += (mouse.deltaX * m_sens) / center_redu
if steering > a_max:
steering = a_max
elif steering < a_min:
steering = a_min
if key_centerx:
steering = 0
# throttle axis
if key_throttle:
th_axis += th_inc
else:
th_axis -= th_dec
if th_axis > th_max:
th_axis = th_max
elif th_axis < a_min:
th_axis = a_min
# brake axis
if key_brake:
br_axis += br_inc
else:
br_axis -= br_dec
if br_axis > br_max:
br_axis = br_max
elif br_axis < a_min:
br_axis = a_min
# handbrake axis
if key_handbrake:
ha_axis += ha_inc
else:
ha_axis -= ha_dec
if ha_axis > a_max:
ha_axis = a_max
elif ha_axis < a_min:
ha_axis = a_min
# clutch axis
if key_clutch:
cl_axis += cl_inc
else:
cl_axis -= cl_dec
if cl_axis > a_max:
cl_axis = a_max
elif cl_axis < a_min:
cl_axis = a_min
# assists switch
if (assists):
if key_shiftup:
th_axis = a_min # throttle cut off while upshifting
if key_shiftdown:
th_axis = a_blip # throttle blip while downshifting
# brake limit
if bl_70:
br_max = a_max * 0.4
if bl_75:
br_max = a_max * 0.5
if bl_80:
br_max = a_max * 0.6
if bl_85:
br_max = a_max * 0.7
if bl_90:
br_max = a_max * 0.8
if bl_95:
br_max = a_max * 0.9
if no_bl:
br_max = a_max
if key_throttle_limit:
th_max = th_limit
else:
th_max = a_max
else: # reset axis position
steering = 0
th_axis = a_min
br_axis = a_min
ha_axis = a_min
cl_axis = a_min

#======== map vjoy axis & button ========#
v.x = int(round(steering))
v.y = th_axis
v.z = br_axis
v.ry = ha_axis
v.rx = cl_axis
v.setButton(1,key_shiftdown)
v.setButton(2,keyboard.getKeyDown(Key.Q))
v.setButton(3,keyboard.getKeyDown(Key.W)) # add new vjoy buttons below

#======== double shifting prevention ========#
if (debouncing):
if key_shiftup:
stimer = 0
elif stimer < t_upshift: # end timer on reaching minimum time
stimer += 1 # start timer on releasing shift button
current = stimer
if key_shiftup and (current >= t_upshift):
v.setButton(0,key_shiftup)
else:
v.setButton(0, False)
else:
v.setButton(0,key_shiftup)

#======== diagnostics ========#
# important note: diagnostics has big impact on cpu usage (about 50-80% more)
# keep this section commented out, only uncomment for coding and testing
#diagnostics.watch(v.x) # steering
#diagnostics.watch(v.y) # throttle
#diagnostics.watch(v.z) # brake
#diagnostics.watch(v.ry) # handbrake
#diagnostics.watch(v.rx) # clutch
#diagnostics.watch(v.axisMax) # vjoy axis max range
#diagnostics.watch(stimer) # shifting timer

#======== reference & example ========#
# vjoy axis: x, y, z, rx, ry, rz, slider, dial
# keyboard assign: keyboard.getKeyDown(Key.A); keyboard.getPressed(Key.A)
# mouse button assign: mouse.getButton(0); mouse.getPressed(1)
# mouse button number: 0 = leftbutton; 1 = rightbutton; 2 = middlebutton; etc.
# to execute an action after pressed a key or clicked mouse button, use: keyboard.getPressed() or mouse.getPressed()
# to execute an action continuously while holding down a key or mouse button, use: keyboard.getKeyDown() or mouse.getButton()

#======== credits ========#
# most codes of "axis calculation" are borrowed from "Skagen", and others found in https://www.lfs.net/forum/post/1862759
# the codes for locking mouse are from https://bytes.com/topic/python/answers/21158-mouse-control-python
# misc codes and formating by threers
# last update: 2018-08-10

var.throttle = keyboard.W
var.brake = keyboard.S
var.clutch = keyboard.C
var.handbrake = keyboard.SPACE
var.shiftup = keyboard.shift
var.shiftdown = keyboard.ctrl
var.headlights = keyboard.L
var.glanceleft = keyboard.Q
var.glanceright = keyboard.E
var.glanceback = keyboard.B
var.changecamera = keyboard.V
var.horn = keyboard.H
var.increasemaxbrake = keyboard.8
var.decreasemaxbrake = keyboard.7
if starting:
system.setThreadTiming(TimingTypes.HighresSystemTimer)
system.threadExecutionInterval = 0

def set_button(button, key):
if keyboard.getKeyDown(key):
v.setButton(button, True)
else:
v.setButton(button, False)

def calculate_rate(max, time):
if time > 0:
return max / (time / system.threadExecutionInterval)
else:
return max

int32_max = (2 ** 14) - 1
int32_min = (( 2** 14) * -1) + 1

v = vJoy[0]
v.x, v.y, v.z, v.rx, v.ry, v.rz, v.slider, v.dial = (int32_min,) * 8

# =============================================================================================
# Axis inversion settings (multiplier): normal = 1; inverted = -1
# =============================================================================================

global throttle_inversion, braking_inversion, clutch_inversion, handbraking_inversion
throttle_inversion = 1
braking_inversion = 1
clutch_inversion = 1
handbraking_inversion = 1

# =============================================================================================
# Mouse settings
# =============================================================================================

global mouse_sensitivity, sensitivity_center_reduction
mouse_sensitivity = 22.5
sensitivity_center_reduction = 2.5

# =============================================================================================
# Steering settings
# =============================================================================================

global steering, steering_max, steering_min, steering_center_reduction

# Init values, do not change

steering = 0.0
steering_max = float(int32_max)
steering_min = float(int32_min)
steering_center_reduction = 1.0

# =============================================================================================
# Throttle settings
# =============================================================================================

# In milliseconds

throttle_increase_time = 0
throttle_decrease_time = 0

global throttle, throttle_max, throttle_min

# Init values, do not change

throttle_max = int32_max * throttle_inversion
throttle_min = int32_min * throttle_inversion
throttle = throttle_min

global throttle_increase_rate, throttle_decrease_rate

# Set throttle behaviour with the increase and decrease time,
# the actual increase and decrease rates are calculated automatically

throttle_increase_rate = calculate_rate(throttle_max, throttle_increase_time)
throttle_decrease_rate = calculate_rate(throttle_max, throttle_decrease_time) * -1

# =============================================================================================
# Braking settings
# =============================================================================================

# In milliseconds

braking_increase_time = 0
braking_decrease_time = 0

global braking, braking_max, braking_min

# Init values, do not change

braking_max = int32_max * braking_inversion
braking_min = int32_min * braking_inversion
braking = braking_min

global braking_increase_rate, braking_decrease_rate

# Set braking behaviour with the increase and decrease time,
# the actual increase and decrease rates are calculated automatically

braking_increase_rate = calculate_rate(braking_max, braking_increase_time)
braking_decrease_rate = calculate_rate(braking_max, braking_decrease_time) * -1

# =============================================================================================
# HandBraking settings
# =============================================================================================

# In milliseconds

handbraking_increase_time = 0
handbraking_decrease_time = 0

global handbraking, handbraking_max, handbraking_min

# Init values, do not change

handbraking_max = int32_max * handbraking_inversion
handbraking_min = int32_min * handbraking_inversion
handbraking = handbraking_min

global handbraking_increase_rate, handbraking_decrease_rate

# Set handbraking behaviour with the increase and decrease time,

# the actual increase and decrease rates are calculated automatically

handbraking_increase_rate = calculate_rate(braking_max, braking_increase_time)
handbraking_decrease_rate = calculate_rate(braking_max, braking_decrease_time) * -1

# =============================================================================================
# Clutch settings
# =============================================================================================

# In milliseconds

clutch_increase_time = 0
clutch_decrease_time = 0

global clutch, clutch_max, clutch_min

# Init values, do not change

clutch_max = int32_max * clutch_inversion
clutch_min = int32_min * clutch_inversion
clutch = clutch_min

global clutch_increase_rate, clutch_decrease_rate

# Set clutch behaviour with the increase and decrease time,
# the actual increase and decrease rates are calculated automatically

clutch_increase_rate = calculate_rate(clutch_max, clutch_increase_time)
clutch_decrease_rate = calculate_rate(clutch_max, clutch_decrease_time) * -1

# =============================================================================================
# Atribuição dos botões em teclas do teclado
# =============================================================================================

vJoy[0].setButton(0,int(keyboard.getKeyDown(Key.A)))
vJoy[0].setButton(1,int(keyboard.getKeyDown(Key.S)))
vJoy[0].setButton(2,int(keyboard.getKeyDown(Key.X)))
vJoy[0].setButton(3,int(keyboard.getKeyDown(Key.D)))
vJoy[0].setButton(4,int(keyboard.getKeyDown(Key.W)))
vJoy[0].setButton(5,int(keyboard.getKeyDown(Key.E)))
vJoy[0].setButton(6,int(keyboard.getKeyDown(Key.R)))
vJoy[0].setButton(7,int(keyboard.getKeyDown(Key.V)))

# =================================================================================================
# Logica da Direção "steering"
# =================================================================================================

if steering > 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_max))
elif steering < 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_min))

steering = steering + ((float(mouse.deltaX) * mouse_sensitivity) / steering_center_reduction)

if steering > steering_max:
steering = steering_max
elif steering < steering_min:
steering = steering_min

v.x = int(round(steering))

# =================================================================================================
# Clutch logic
# =================================================================================================

if keyboard.getKeyDown(Key.C):
clutch = clutch + clutch_increase_rate
else:
clutch = clutch + clutch_decrease_rate

if clutch > clutch_max * clutch_inversion:
clutch = clutch_max * clutch_inversion
elif clutch < clutch_min * clutch_inversion:
clutch = clutch_min * clutch_inversion

v.slider = clutch

# =================================================================================================
# Throttle logic
# =================================================================================================

if mouse.leftButton:
throttle = throttle + throttle_increase_rate
else:
throttle = throttle + throttle_decrease_rate

if throttle > throttle_max * throttle_inversion:
throttle = throttle_max * throttle_inversion
elif throttle < throttle_min * throttle_inversion:
throttle = throttle_min * throttle_inversion

v.y = throttle

# =================================================================================================
# Braking logic
# =================================================================================================

if mouse.rightButton:
braking = braking + braking_increase_rate
else:
braking = braking + braking_decrease_rate

if braking > braking_max * braking_inversion:
braking = braking_max * braking_inversion
elif braking < braking_min * braking_inversion:
braking = braking_min * braking_inversion

v.z = braking

# =================================================================================================
# HandBraking logic
# =================================================================================================

if keyboard.getKeyDown(Key.Q):
handbraking = handbraking + handbraking_increase_rate
else:
handbraking = handbraking + handbraking_decrease_rate

if handbraking > handbraking_max * handbraking_inversion:
handbraking = handbraking_max * handbraking_inversion
elif handbraking < handbraking_min * handbraking_inversion:
handbraking = handbraking_min * handbraking_inversion

v.rx = handbraking

# =================================================================================================
# PIE diagnostics logic
# =================================================================================================

diagnostics.watch(v.x)
diagnostics.watch(v.y)
diagnostics.watch(v.z)
diagnostics.watch(v.rx)
diagnostics.watch(v.slider)
diagnostics.watch(steering_center_reduction)

from ctypes import *
user32 = windll.user32

if starting:
mouselock = False

toggle_mouselock = keyboard.getPressed(Key.O)

if toggle_mouselock:
mouselock = not mouselock
if (mouselock):
user32.SetCursorPos(0, 5000)
basic Rally config
if starting:
system.setThreadTiming(TimingTypes.HighresSystemTimer)
system.threadExecutionInterval = 0

def set_button(button, key):
if keyboard.getKeyDown(key):
v.setButton(button, True)
else:
v.setButton(button, False)

def calculate_rate(max, time):
if time > 0:
return max / (time / system.threadExecutionInterval)
else:
return max

int32_max = (2 ** 14) - 1
int32_min = (( 2** 14) * -1) + 1

v = vJoy[0]
v.x, v.y, v.z, v.rx, v.ry, v.rz, v.slider, v.dial = (int32_min,) * 8

# =============================================================================================
# Axis inversion settings (multiplier): normal = 1; inverted = -1
# =============================================================================================

global throttle_inversion, braking_inversion, clutch_inversion, handbraking_inversion
throttle_inversion = 1
braking_inversion = 1
clutch_inversion = 1
handbraking_inversion = 1

# =============================================================================================
# Mouse settings
# =============================================================================================

global mouse_sensitivity, sensitivity_center_reduction
mouse_sensitivity = 22.5
sensitivity_center_reduction = 2.5

# =============================================================================================
# Ignition cut settings
# =============================================================================================

global ignition_cut_time, ignition_cut_elapsed_time
ignition_cut_enabled = True
ignition_cut_time = 0
ignition_cut_elapsed_time = 0

global ignition_cut, ignition_cut_released

# Init values, do not change

ignition_cut = True
ignition_cut_released = True

# =============================================================================================
# Steering settings
# =============================================================================================

global steering, steering_max, steering_min, steering_center_reduction

# Init values, do not change

steering = 0.0
steering_max = float(int32_max)
steering_min = float(int32_min)
steering_center_reduction = 1.0

# =============================================================================================
# Throttle settings
# =============================================================================================

global throttle_blip_enabled
throttle_blip_enabled = True

# In milliseconds

throttle_increase_time = 0
throttle_increase_time_after_ignition_cut = 0
throttle_increase_time_blip = 0
throttle_decrease_time = 0

global throttle, throttle_max, throttle_min

# Init values, do not change

throttle_max = int32_max * throttle_inversion
throttle_min = int32_min * throttle_inversion
throttle = throttle_min

global throttle_increase_rate, throttle_decrease_rate

# Set throttle behaviour with the increase and decrease time,
# the actual increase and decrease rates are calculated automatically

throttle_increase_rate = calculate_rate(throttle_max, throttle_increase_time)
throttle_increase_rate_after_ignition_cut = calculate_rate(throttle_max, throttle_increase_time_after_ignition_cut)
throttle_increase_rate_blip = calculate_rate(throttle_max, throttle_increase_time_blip)
throttle_decrease_rate = calculate_rate(throttle_max, throttle_decrease_time) * -1

# =============================================================================================
# Braking settings
# =============================================================================================

# In milliseconds

braking_increase_time = 0
braking_decrease_time = 0

global braking, braking_max, braking_min

# Init values, do not change

braking_max = int32_max * braking_inversion
braking_min = int32_min * braking_inversion
braking = braking_min

global braking_increase_rate, braking_decrease_rate

# Set braking behaviour with the increase and decrease time,

# the actual increase and decrease rates are calculated automatically

braking_increase_rate = calculate_rate(braking_max, braking_increase_time)
braking_decrease_rate = calculate_rate(braking_max, braking_decrease_time) * -1

# =============================================================================================
# HandBraking settings
# =============================================================================================

# In milliseconds

handbraking_increase_time = 0
handbraking_decrease_time = 0

global handbraking, handbraking_max, handbraking_min

# Init values, do not change

handbraking_max = int32_max * handbraking_inversion
handbraking_min = int32_min * handbraking_inversion
handbraking = handbraking_min

global handbraking_increase_rate, handbraking_decrease_rate

# Set handbraking behaviour with the increase and decrease time,

# the actual increase and decrease rates are calculated automatically

handbraking_increase_rate = calculate_rate(braking_max, braking_increase_time)
handbraking_decrease_rate = calculate_rate(braking_max, braking_decrease_time) * -1

# =============================================================================================
# Clutch settings
# =============================================================================================

# In milliseconds

clutch_increase_time = 0
clutch_decrease_time = 0

global clutch, clutch_max, clutch_min

# Init values, do not change

clutch_max = int32_max * clutch_inversion
clutch_min = int32_min * clutch_inversion
clutch = clutch_min

global clutch_increase_rate, clutch_decrease_rate

# Set clutch behaviour with the increase and decrease time,
# the actual increase and decrease rates are calculated automatically

clutch_increase_rate = calculate_rate(clutch_max, clutch_increase_time)
clutch_decrease_rate = calculate_rate(clutch_max, clutch_decrease_time) * -1

# =============================================================================================
# Atribuição dos botões em teclas do teclado
# =============================================================================================

vJoy[0].setButton(0,int(keyboard.getKeyDown(Key.A)))
vJoy[0].setButton(1,int(keyboard.getKeyDown(Key.S)))
vJoy[0].setButton(2,int(keyboard.getKeyDown(Key.X)))
vJoy[0].setButton(3,int(keyboard.getKeyDown(Key.D)))
vJoy[0].setButton(4,int(keyboard.getKeyDown(Key.W)))
vJoy[0].setButton(5,int(keyboard.getKeyDown(Key.E)))
vJoy[0].setButton(6,int(keyboard.getKeyDown(Key.R)))
vJoy[0].setButton(7,int(keyboard.getKeyDown(Key.V)))

# =================================================================================================
# Logica da Direção "steering"
# =================================================================================================

if steering > 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_max))
elif steering < 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_min))

steering = steering + ((float(mouse.deltaX) * mouse_sensitivity) / steering_center_reduction)

if steering > steering_max:
steering = steering_max
elif steering < steering_min:
steering = steering_min

v.x = int(round(steering))

# =================================================================================================
# Clutch logic
# =================================================================================================

if (throttle_blip_enabled and keyboard.getKeyDown(Key.X)) or (ignition_cut_enabled and ignition_cut_released and keyboard.getKeyDown(Key.S)) or keyboard.getKeyDown(Key.C):
clutch = clutch_max
else:
clutch = clutch + clutch_decrease_rate

if clutch > clutch_max * clutch_inversion:
clutch = clutch_max * clutch_inversion
elif clutch < clutch_min * clutch_inversion:
clutch = clutch_min * clutch_inversion

v.slider = clutch

# =================================================================================================
# Throttle logic
# =================================================================================================

if ignition_cut_enabled and ignition_cut and ignition_cut_elapsed_time < ignition_cut_time:
ignition_cut_elapsed_time = ignition_cut_elapsed_time + system.threadExecutionInterval

if ignition_cut_enabled and not ignition_cut_released and keyboard.getKeyUp(Key.X):
ignition_cut_released = False

if throttle_blip_enabled and ((ignition_cut_enabled and not ignition_cut) or (not ignition_cut_enabled)) and keyboard.getKeyDown(Key.X):
# Throttle blip
throttle = throttle + throttle_increase_rate_blip
elif ignition_cut_enabled and ignition_cut_released and keyboard.getKeyDown(Key.S):
# Ignition cut
throttle = throttle_min
ignition_cut = False
ignition_cut_released = True
ignition_cut_elapsed_time = 0
elif mouse.leftButton:
if ignition_cut_enabled and ignition_cut and ignition_cut_elapsed_time >= ignition_cut_time:
throttle = throttle_max
else:
throttle = throttle + throttle_increase_rate
else:
throttle = throttle + throttle_decrease_rate

if ignition_cut_enabled and ignition_cut and ignition_cut_elapsed_time >= ignition_cut_time:
ignition_cut = True
ignition_cut_elapsed_time = 0

if throttle > throttle_max * throttle_inversion:
throttle = throttle_max * throttle_inversion
elif throttle < throttle_min * throttle_inversion:
throttle = throttle_min * throttle_inversion

v.y = throttle

# =================================================================================================
# Braking logic
# =================================================================================================

if mouse.rightButton:
braking = braking + braking_increase_rate
else:
braking = braking + braking_decrease_rate

if braking > braking_max * braking_inversion:
braking = braking_max * braking_inversion
elif braking < braking_min * braking_inversion:
braking = braking_min * braking_inversion

v.z = braking

# =================================================================================================
# HandBraking logic
# =================================================================================================

if keyboard.getKeyDown(Key.Q):
handbraking = handbraking + handbraking_increase_rate
else:
handbraking = handbraking + handbraking_decrease_rate

if handbraking > handbraking_max * handbraking_inversion:
handbraking = handbraking_max * handbraking_inversion
elif handbraking < handbraking_min * handbraking_inversion:
handbraking = handbraking_min * handbraking_inversion

v.rx = handbraking

# =================================================================================================
# PIE diagnostics logic
# =================================================================================================

diagnostics.watch(v.x)
diagnostics.watch(v.y)
diagnostics.watch(v.z)
diagnostics.watch(v.rx)
diagnostics.watch(v.slider)
diagnostics.watch(steering_center_reduction)
diagnostics.watch(throttle_blip_enabled)
diagnostics.watch(ignition_cut_enabled)


from ctypes import *
user32 = windll.user32

if starting:
mouselock = False

toggle_mouselock = keyboard.getPressed(Key.O)

if toggle_mouselock:
mouselock = not mouselock
if (mouselock):
user32.SetCursorPos(0, 5000)
FBM config 1:11:40 xD
if starting:
system.setThreadTiming(TimingTypes.HighresSystemTimer)
system.threadExecutionInterval = 0

def set_button(button, key):
if keyboard.getKeyDown(key):
v.setButton(button, True)
else:
v.setButton(button, False)

def calculate_rate(max, time):
if time > 0:
return max / (time / system.threadExecutionInterval)
else:
return max

int32_max = (2 ** 14) - 1
int32_min = (( 2** 14) * -1) + 1
int32_mid = 0

v = vJoy[0]
v.x, v.y, v.z, v.rx, v.ry, v.rz, v.slider, v.dial = (int32_min,) * 8

# =============================================================================================
# Axis inversion settings (multiplier): normal = 1; inverted = -1
# =============================================================================================

global throttle_inversion, braking_inversion, clutch_inversion, handbraking_inversion
throttle_inversion = 1
braking_inversion = 1
clutch_inversion = 1
handbraking_inversion = 1

# =============================================================================================
# Mouse settings
# =============================================================================================

global mouse_sensitivity, sensitivity_center_reduction
mouse_sensitivity = 22.5
sensitivity_center_reduction = 2.5

# =============================================================================================
# Steering settings
# =============================================================================================

global steering, steering_max, steering_min, steering_center_reduction

# Init values, do not change

steering = 0
steering_max = float(int32_max)
steering_min = float(int32_min)
steering_center_reduction = 1

# =============================================================================================
# Throttle settings
# =============================================================================================

# In milliseconds

throttle_increase_time = 0
throttle_decrease_time = 0

global throttle, throttle_max, throttle_min, throttle_mid

# Init values, do not change

throttle_max = int32_max * throttle_inversion
throttle_min = int32_min * throttle_inversion
throttle_mid = int32_mid
throttle = throttle_min

global throttle_increase_rate, throttle_decrease_rate

# Set throttle behaviour with the increase and decrease time,
# the actual increase and decrease rates are calculated automatically

throttle_increase_rate = calculate_rate(throttle_max, throttle_increase_time)
throttle_decrease_rate = calculate_rate(throttle_max, throttle_decrease_time) * -1

# =============================================================================================
# Ignition cut settings
# =============================================================================================

global ignition_cut, ignition_cut_released
ignition_cut = True
ignition_cut_released = True

# =============================================================================================
# Braking settings
# =============================================================================================

# In milliseconds

braking_increase_time = 0
braking_decrease_time = 0

global braking, braking_max, braking_min

# Init values, do not change

braking_max = int32_max * braking_inversion
braking_min = int32_min * braking_inversion
braking = braking_min

global braking_increase_rate, braking_decrease_rate

# Set braking behaviour with the increase and decrease time,

# the actual increase and decrease rates are calculated automatically

braking_increase_rate = calculate_rate(braking_max, braking_increase_time)
braking_decrease_rate = calculate_rate(braking_max, braking_decrease_time) * -1

# =============================================================================================
# HandBraking settings
# =============================================================================================

# In milliseconds

handbraking_increase_time = 0
handbraking_decrease_time = 0

global handbraking, handbraking_max, handbraking_min

# Init values, do not change

handbraking_max = int32_max * handbraking_inversion
handbraking_min = int32_min * handbraking_inversion
handbraking = handbraking_min

global handbraking_increase_rate, handbraking_decrease_rate

# Set handbraking behaviour with the increase and decrease time,

# the actual increase and decrease rates are calculated automatically

handbraking_increase_rate = calculate_rate(braking_max, braking_increase_time)
handbraking_decrease_rate = calculate_rate(braking_max, braking_decrease_time) * -1

# =============================================================================================
# Clutch settings
# =============================================================================================

# In milliseconds

clutch_increase_time = 0
clutch_decrease_time = 0

global clutch, clutch_max, clutch_min

# Init values, do not change

clutch_max = int32_max * clutch_inversion
clutch_min = int32_min * clutch_inversion
clutch = clutch_min

global clutch_increase_rate, clutch_decrease_rate

# Set clutch behaviour with the increase and decrease time,
# the actual increase and decrease rates are calculated automatically

clutch_increase_rate = calculate_rate(clutch_max, clutch_increase_time)
clutch_decrease_rate = calculate_rate(clutch_max, clutch_decrease_time) * -1

# =============================================================================================
# Atribuição dos botões em teclas do teclado
# =============================================================================================

vJoy[0].setButton(0,int(keyboard.getKeyDown(Key.Z)))
vJoy[0].setButton(1,int(keyboard.getKeyDown(Key.S)))
vJoy[0].setButton(2,int(keyboard.getKeyDown(Key.X)))
vJoy[0].setButton(3,int(keyboard.getKeyDown(Key.D)))
vJoy[0].setButton(4,int(keyboard.getKeyDown(Key.W)))
vJoy[0].setButton(5,int(keyboard.getKeyDown(Key.E)))
vJoy[0].setButton(6,int(keyboard.getKeyDown(Key.R)))
vJoy[0].setButton(7,int(keyboard.getKeyDown(Key.V)))

# =================================================================================================
# Logica da Direção "steering"
# =================================================================================================

if steering > 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_max))
elif steering < 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_min))

steering = steering + ((float(mouse.deltaX) * mouse_sensitivity) / steering_center_reduction)

if steering > steering_max:
steering = steering_max
elif steering < steering_min:
steering = steering_min

v.x = int(round(steering))

# =================================================================================================
# Clutch logic
# =================================================================================================

if keyboard.getKeyDown(Key.C):
clutch = clutch + clutch_increase_rate
else:
clutch = clutch + clutch_decrease_rate

if clutch > clutch_max * clutch_inversion:
clutch = clutch_max * clutch_inversion
elif clutch < clutch_min * clutch_inversion:
clutch = clutch_min * clutch_inversion

v.slider = clutch

# =================================================================================================
# Throttle logic
# =================================================================================================

if mouse.leftButton:
throttle = throttle + throttle_increase_rate
else:
throttle = throttle + throttle_decrease_rate

if throttle > throttle_max * throttle_inversion:
throttle = throttle_max * throttle_inversion
elif throttle < throttle_min * throttle_inversion:
throttle = throttle_min * throttle_inversion

if keyboard.getKeyDown(Key.S) and ignition_cut:
throttle = throttle_mid
elif keyboard.getKeyDown(Key.A):
throttle = throttle_mid

v.y = throttle

# =================================================================================================
# Braking logic
# =================================================================================================

if mouse.rightButton:
braking = braking + braking_increase_rate
else:
braking = braking + braking_decrease_rate

if braking > braking_max * braking_inversion:
braking = braking_max * braking_inversion
elif braking < braking_min * braking_inversion:
braking = braking_min * braking_inversion

v.z = braking

# =================================================================================================
# HandBraking logic
# =================================================================================================

if keyboard.getKeyDown(Key.Q):
handbraking = handbraking + handbraking_increase_rate
else:
handbraking = handbraking + handbraking_decrease_rate

if handbraking > handbraking_max * handbraking_inversion:
handbraking = handbraking_max * handbraking_inversion
elif handbraking < handbraking_min * handbraking_inversion:
handbraking = handbraking_min * handbraking_inversion

v.rx = handbraking

# =================================================================================================
# PIE diagnostics logic
# =================================================================================================

diagnostics.watch(v.x)
diagnostics.watch(v.y)
diagnostics.watch(v.z)
diagnostics.watch(v.rx)
diagnostics.watch(v.slider)
diagnostics.watch(steering_center_reduction)
diagnostics.watch(ignition_cut)
diagnostics.watch(ignition_cut_released)

from ctypes import *
user32 = windll.user32

if starting:
mouselock = False

toggle_mouselock = keyboard.getPressed(Key.O)

if toggle_mouselock:
mouselock = not mouselock
if (mouselock):
user32.SetCursorPos(0, 5000)
steering wheel config VJOY, put j = joystick[0] device.getDown(0) (float(j.x)
if starting:
system.setThreadTiming(TimingTypes.HighresSystemTimer)
system.threadExecutionInterval = 0

def set_button(button, key):
if keyboard.getKeyDown(key):
v.setButton(button, True)
else:
v.setButton(button, False)

def calculate_rate(max, time):
if time > 0:
return max / (time / system.threadExecutionInterval)
else:
return max

int32_max = (2 ** 14) - 1
int32_min = (( 2** 14) * -1) + 1
int32_mid = 0

j = joystick[1]

j.x, j.y, j.zRotation

v = vJoy[0]

v.x, v.y, v.z, v.rx, v.ry, v.rz, v.slider, v.dial = (int32_min,) * 8

# =============================================================================================
# Axis inversion settings (multiplier): normal = 1; inverted = -1
# =============================================================================================

global throttle_inversion, braking_inversion, clutch_inversion, handbraking_inversion
throttle_inversion = -1
braking_inversion = -1
clutch_inversion = -1
handbraking_inversion = -1

# =============================================================================================
# Global sensitivity settings
# =============================================================================================

global sensitivity, sensitivity_center_reduction
sensitivity_center_reduction = 2.4
sensitivity = 16.5

# =============================================================================================
# Steering settings
# =============================================================================================

global steering, steering_max, steering_min, steering_center_reduction

# Init values, do not change

steering = 0
steering_max = float(int32_max)
steering_min = float(int32_min)
steering_center_reduction = 1

# =============================================================================================
# Throttle settings
# =============================================================================================

global throttle, throttle_max, throttle_min

# Init values, do not change

throttle_max = int32_max * throttle_inversion
throttle_min = int32_min * throttle_inversion
throttle_mid = int32_mid
throttle = int32_min

# =============================================================================================
# Ignition cut settings
# =============================================================================================

global ignition_cut, ignition_cut_released
ignition_cut = True
ignition_cut_released = True

# =============================================================================================
# Braking settings
# =============================================================================================

global braking, braking_max, braking_min

# Init values, do not change

braking_max = int32_max * braking_inversion
braking_min = int32_min * braking_inversion
braking = int32_min

# =============================================================================================
# HandBraking settings
# =============================================================================================

# In milliseconds

handbraking_increase_time = 0
handbraking_decrease_time = 0

global handbraking, handbraking_max, handbraking_min

# Init values, do not change

handbraking_max = int32_max * handbraking_inversion
handbraking_min = int32_min * handbraking_inversion
handbraking = handbraking_min

global handbraking_increase_rate, handbraking_decrease_rate

# Set handbraking behaviour with the increase and decrease time,

# the actual increase and decrease rates are calculated automatically

handbraking_increase_rate = calculate_rate(handbraking_max, handbraking_increase_time)
handbraking_decrease_rate = calculate_rate(handbraking_max, handbraking_decrease_time) * -1

# =============================================================================================
# Clutch settings
# =============================================================================================

# In milliseconds

clutch_increase_time = 0
clutch_decrease_time = 0

global clutch, clutch_max, clutch_min

# Init values, do not change

clutch_max = int32_max * clutch_inversion
clutch_min = int32_min * clutch_inversion
clutch = clutch_min

global clutch_increase_rate, clutch_decrease_rate

# Set clutch behaviour with the increase and decrease time,
# the actual increase and decrease rates are calculated automatically

clutch_increase_rate = calculate_rate(clutch_max, clutch_increase_time)
clutch_decrease_rate = calculate_rate(clutch_max, clutch_decrease_time) * -1

# =============================================================================================
# Atribuição dos botões em teclas do teclado
# =============================================================================================

v.setButton(0,int(j.getDown(0)))
v.setButton(1,int(j.getDown(1)))
v.setButton(2,int(j.getDown(2)))
v.setButton(3,int(j.getDown(3)))
v.setButton(4,int(j.getDown(4)))
v.setButton(5,int(j.getDown(5)))
v.setButton(6,int(j.getDown(6)))
v.setButton(7,int(j.getDown(7)))

# =================================================================================================
# Logica da Direção "steering"
# =================================================================================================

if steering > 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_max))
elif steering < 0:
steering_center_reduction = sensitivity_center_reduction ** (1 - (steering / steering_min))

steering = ((float(j.x) * sensitivity) / steering_center_reduction)

if steering > steering_max:
steering = steering_max
elif steering < steering_min:
steering = steering_min

v.x = int(round(steering))

# =================================================================================================
# Throttle logic
# =================================================================================================

if throttle:
throttle = (1 - (throttle / throttle_max))
elif throttle:
throttle = (1 - (throttle / throttle_min))

throttle = throttle + ((float(j.y) * sensitivity))

if throttle > throttle_max * throttle_inversion:
throttle = throttle_max * throttle_inversion
elif throttle < throttle_min * throttle_inversion:
throttle = throttle_min * throttle_inversion

if joystick[0].getDown(7) and ignition_cut:
throttle = throttle_mid

v.y = int(round(throttle))

# =================================================================================================
# Braking logic
# =================================================================================================

if braking:
braking = (1 - (braking / braking_max))
elif braking:
braking = (1 - (braking / braking_min))

braking = braking + ((float(j.zRotation) * sensitivity))

if braking > braking_max * braking_inversion:
braking = braking_max * braking_inversion
elif braking < braking_min * braking_inversion:
braking = braking_min * braking_inversion

v.z = int(round(braking))

# =================================================================================================
# Clutch logic
# =================================================================================================
if joystick[0].getDown(3):
clutch = clutch + clutch_increase_rate
else:
clutch = clutch + clutch_decrease_rate

if clutch > clutch_max * clutch_inversion:
clutch = clutch_max * clutch_inversion
elif clutch < clutch_min * clutch_inversion:
clutch = clutch_min * clutch_inversion

v.slider = clutch

# =================================================================================================
# HandBraking logic
# =================================================================================================

if keyboard.getKeyDown(Key.Q):
handbraking = handbraking + handbraking_increase_rate
else:
handbraking = handbraking + handbraking_decrease_rate

if handbraking > handbraking_max * handbraking_inversion:
handbraking = handbraking_max * handbraking_inversion
elif handbraking < handbraking_min * handbraking_inversion:
handbraking = handbraking_min * handbraking_inversion

v.rx = handbraking

# =================================================================================================
# PIE diagnostics logic
# =================================================================================================

diagnostics.watch(j.x)
diagnostics.watch(j.y)
diagnostics.watch(j.zRotation)
diagnostics.watch(v.x)
diagnostics.watch(v.y)
diagnostics.watch(v.z)
diagnostics.watch(v.rx)
diagnostics.watch(v.slider)
diagnostics.watch(steering_center_reduction)
2

(Update: bug fixed) vJoy + FreePIE for scripting virtual controllers
(45 posts, started )
FGED GREDG RDFGDR GSFDG