Code: Select all
# Script created by VerdeMsk using ChatGPT. Version 0.1
if starting:
# Settings
# Define the switch: 1 for hydra[0] - left, 2 for hydra[1] - right
hydra_switch = 2 # Change this value to 1 or 2 to switch between Hydra - left and Hydra - right
# Define the switch: 1 for hydra[0].yaw, 2 for hydra[0].roll
translation_switch = 1 # Change this value to 1 or 2 to switch between yaw and roll
v = vJoy[0]
v.x, v.y, v.z, v.rx, v.ry, v.rz, v.slider, v.dial = (0,) * 8 # Reset vJoy axes to 0 initially
global yaw_sensitivity, roll_sensitivity, pitch_sensitivity, left_stick_sensitivity
global left_trigger_sensitivity, right_trigger_sensitivity
yaw_sensitivity = 1 # Adjust the sensitivity for yaw as needed
roll_sensitivity = 1 # Adjust the sensitivity for the roll axis as needed
pitch_sensitivity = 1 # Adjust the sensitivity for pitch as needed
left_stick_sensitivity = 1 # Adjust the sensitivity for the left stick as needed
left_trigger_sensitivity = 1 # Adjust the sensitivity for left trigger as needed
right_trigger_sensitivity = 1 # Adjust the sensitivity for right trigger as needed
# Define vJoy X, Y, Z, Rx, Ry, Rz, Slider, and Dial axis maximum and minimum range
vjoy_x_max = 16383
vjoy_x_min = -16383
vjoy_y_max = 16383
vjoy_y_min = -16383
vjoy_z_max = 16383
vjoy_z_min = -16383
vjoy_rx_max = 16383
vjoy_rx_min = -16383
vjoy_ry_max = 16383
vjoy_ry_min = -16383
vjoy_rz_max = 16383
vjoy_rz_min = -16383
vjoy_slider_max = 16383
vjoy_slider_min = -16383
vjoy_dial_max = 16383
vjoy_dial_min = -16383
# Calculate the ratio to map Hydra yaw, pitch, left stick, triggers, and second stick to vJoy axes range
yaw_to_vjoy_x_ratio = vjoy_x_max / 1.0 # Maximum Hydra yaw (adjust this value if needed)
roll_to_vjoy_x_ratio = vjoy_x_max / 1.0 # Maximum Hydra roll (adjust this value if needed)
pitch_to_vjoy_y_ratio = vjoy_y_max / 1.0 # Maximum Hydra pitch (adjust this value if needed)
left_stick_to_vjoy_rx_ratio = vjoy_rx_max / 1.0 # Maximum Hydra left stick axis (adjust this value if needed)
left_stick_to_vjoy_ry_ratio = vjoy_ry_max / 1.0 # Maximum Hydra left stick axis (adjust this value if needed)
trigger_to_vjoy_z_ratio = vjoy_z_max / 1.0 # Maximum Hydra trigger (adjust this value if needed)
trigger_to_vjoy_rz_ratio = vjoy_rz_max / 1.0 # Maximum Hydra trigger (adjust this value if needed)
joy_to_vjoy_slider_ratio = vjoy_slider_max / 1.0 # Maximum Hydra joyx (adjust this value if needed)
joy_to_vjoy_dial_ratio = vjoy_dial_max / 1.0 # Maximum Hydra joyy (adjust this value if needed)
if hydra[0].yaw or hydra[0].roll or hydra[0].pitch or hydra[0].joyx or hydra[0].joyy or hydra[0].trigger or hydra[1].trigger or hydra[1].joyx or hydra[1].joyy:
# Update Hydra values using Razer Hydra controller data
if hydra_switch == 1:
yaw = hydra[0].yaw * yaw_sensitivity
roll = hydra[0].roll * roll_sensitivity
pitch = hydra[0].pitch * pitch_sensitivity
elif hydra_switch == 2:
yaw = hydra[1].yaw * yaw_sensitivity
roll = hydra[1].roll * roll_sensitivity
pitch = hydra[1].pitch * pitch_sensitivity
# Use the switch to determine what to map to vJoy x-axis
if translation_switch == 1:
v.x = max(vjoy_x_min, min(vjoy_x_max, int(round(yaw * yaw_to_vjoy_x_ratio))))
elif translation_switch == 2:
v.x = max(vjoy_x_min, min(vjoy_x_max, int(round(roll * roll_to_vjoy_x_ratio))))
left_stick_x = hydra[0].joyx * left_stick_sensitivity
left_stick_y = hydra[0].joyy * left_stick_sensitivity
left_trigger = hydra[0].trigger * left_trigger_sensitivity
right_trigger = hydra[1].trigger * right_trigger_sensitivity
joy_x = hydra[1].joyx * left_stick_sensitivity
joy_y = hydra[1].joyy * left_stick_sensitivity
# Map Hydra pitch to vJoy Y-axis range centered around 0
v.y = max(vjoy_y_min, min(vjoy_y_max, int(round(-pitch * pitch_to_vjoy_y_ratio))))
# Map Hydra left stick x-axis to vJoy Rx-axis
v.rx = max(vjoy_rx_min, min(vjoy_rx_max, int(round(left_stick_x * left_stick_to_vjoy_rx_ratio))))
# Map Hydra left stick y-axis to vJoy Ry-axis
v.ry = max(vjoy_ry_min, min(vjoy_ry_max, int(round(-left_stick_y * left_stick_to_vjoy_ry_ratio))))
# Map Hydra left trigger to vJoy Slider axis
v.z = max(vjoy_z_min, min(vjoy_z_max, int(round(joy_x * joy_to_vjoy_slider_ratio))))
# Map Hydra right trigger to vJoy Rz-axis
v.rz = max(vjoy_rz_min, min(vjoy_rz_max, int(round(-joy_y * joy_to_vjoy_dial_ratio))))
# Map Hydra joyx to vJoy Z-axis
v.slider = max(vjoy_slider_min, min(vjoy_slider_max, int(round(left_trigger * trigger_to_vjoy_z_ratio))))
# Map Hydra joyy to vJoy Dial axis
v.dial = max(vjoy_dial_min, min(vjoy_dial_max, int(round(right_trigger * trigger_to_vjoy_rz_ratio))))
#Buttons
vJoy[0].setButton(0,int(hydra[0].one))
vJoy[0].setButton(1,int(hydra[0].two))
vJoy[0].setButton(2,int(hydra[0].three))
vJoy[0].setButton(3,int(hydra[0].four))
vJoy[0].setButton(4,int(hydra[1].one))
vJoy[0].setButton(5,int(hydra[1].two))
vJoy[0].setButton(6,int(hydra[1].three))
vJoy[0].setButton(7,int(hydra[1].four))
vJoy[0].setButton(8,int(hydra[0].start))
vJoy[0].setButton(9,int(hydra[1].start))
vJoy[0].setButton(10,int(hydra[0].bumper))
vJoy[0].setButton(11,int(hydra[1].bumper))
vJoy[0].setButton(12,int(hydra[0].joybutton))
vJoy[0].setButton(13,int(hydra[1].joybutton))
diagnostics.watch(hydra[0].yaw)
#diagnostics.watch(hydra[0].roll)
#diagnostics.watch(hydra[0].pitch)
diagnostics.watch(hydra[1].yaw)
#diagnostics.watch(hydra[1].roll)
#diagnostics.watch(hydra[1].pitch)
#diagnostics.watch(vJoy[0].x)
#diagnostics.watch(v.x)
#diagnostics.watch(hydra[0].trigger)
#diagnostics.watch(hydra[1].trigger)
#diagnostics.watch(vJoy[0].z)
#diagnostics.watch(v.z)