'Python, FreePIE emulator mod for mad max

I have a little python script from a modder that made it possible for mad max to walk on PC. He uses freePie to emulate a joystick and that way you can toggle with shift and Ctrl,the speed in which Max walks. The thing is the script joystick feels extremely sticky and slow as it tries to emulate a joystick with mouse and keyboard, and there is no way to get past that it seems.. Here is the script

# Walk Toggle script for Mad Max (PC)
# by STELLAR-7 Project

# Starting variables
if starting:
    vJoy[0].x = 0
    vJoy[0].y = 0
    vJoy[0].z = 0
    vJoy[0].rx = 0
    vJoy[0].ry = 0
    vJoy[0].rz = 0
    up = 0
    left = 0
    down = 0
    right = 0
    isMoving = 0
    moveMode = 0
    axisMax = vJoy[0].axisMax
    axis = axisMax * 0.85
    mouseSmooth = 0
    mouseSens = 5000
    

# Movement toggle RUN-JOG-WALK key (LeftControl)
if keyboard.getPressed(Key.NumberPad0): 


if keyboard.getPressed(Key.LeftControl):
    if moveMode > 0:
        moveMode -= 1
    if moveMode == 0:
        axis = axisMax * 0.75
    else:
        axis = axisMax * 0.81
# Movement toggle WALK-JOG-RUN key (LeftShift)
elif keyboard.getPressed(Key.LeftShift):
    if moveMode < 2:
        moveMode += 1
    if moveMode == 1:
        axis = axisMax * 0.81
    else:
        axis = axisMax

# Get keyboard movement (WASD)
if keyboard.getKeyDown(Key.W):
    isMoving = 1
    up = 1
else:
    up = 0

if keyboard.getKeyDown(Key.A):
    isMoving = 1
    left = 1
else:
    left = 0

if keyboard.getKeyDown(Key.S):
    isMoving = 1
    down = 1
else:
    down = 0

if keyboard.getKeyDown(Key.D):
    isMoving = 1
    right = 1
else:
    right = 0

# Process movement
# Diagonals first...
if up == 1 and right == 1:
    vJoy[0].x = axis * 0.7
    vJoy[0].y = -axis * 0.7
elif up == 1 and left == 1:
    vJoy[0].x = -axis * 0.7
    vJoy[0].y = -axis * 0.7
elif down == 1 and left == 1:
    vJoy[0].x = -axis * 0.7
    vJoy[0].y = axis * 0.7
elif down == 1 and right == 1:
    vJoy[0].x = axis * 0.7
    vJoy[0].y = axis * 0.7
elif up == 1:
    vJoy[0].x = 0
    vJoy[0].y = -axis
elif left == 1:
    vJoy[0].x = -axis
    vJoy[0].y = 0
elif down == 1:
    vJoy[0].x = 0
    vJoy[0].y = axis
elif right == 1:
    vJoy[0].x = axis
    vJoy[0].y = 0
else:
    isMoving = 0
    vJoy[0].x = 0
    vJoy[0].y = 0

# Mouse look
if isMoving == 1:
    vJoy[0].z = -mouse.deltaX * mouseSmooth
    vJoy[0].ry = mouse.deltaY * mouseSmooth
    if mouseSmooth < mouseSens:
        mouseSmooth += 10
else:
    mouseSmooth = 0
    vJoy[0].z = 0
    vJoy[0].ry = 0

Is there any way that I can make the script completely stop on a button toggle or keypress. Kind of like turning it on and off. Say for instance if I press numpad0 the script must stop working, as the controls in vehicles is just impossible to work with. This needs to happen in game though. Can this script be refined a bit? Or maybe even stop working while the mouse is active.

Here is the original mod. https://www.nexusmods.com/madmax/mods/9?tab=posts



Solution 1:[1]

# Walk Toggle script for Mad Max (PC)
# by STELLAR-7 Project

# Starting variables
if starting:
    stopGame = 0
    vJoy[0].x = 0
    vJoy[0].y = 0
    vJoy[0].z = 0
    vJoy[0].rx = 0
    vJoy[0].ry = 0
    vJoy[0].rz = 0
    up = 0
    left = 0
    down = 0
    right = 0
    isMoving = 0
    moveMode = 0
    axisMax = vJoy[0].axisMax
    axis = axisMax * 0.85
    mouseSmooth = 0
    mouseSens = 5000
    

# Movement toggle RUN-JOG-WALK key (LeftControl)
if keyboard.getPressed(Key.NumberPad0):
    stopGame = 1 - stopGame


if keyboard.getPressed(Key.LeftControl):
    if moveMode > 0:
        moveMode -= 1
    if moveMode == 0:
        axis = axisMax * 0.75
    else:
        axis = axisMax * 0.81
# Movement toggle WALK-JOG-RUN key (LeftShift)
elif keyboard.getPressed(Key.LeftShift):
    if moveMode < 2:
        moveMode += 1
    if moveMode == 1:
        axis = axisMax * 0.81
    else:
        axis = axisMax

if stopGame == 0:
# Get keyboard movement (WASD)
    if keyboard.getKeyDown(Key.W):
        isMoving = 1
        up = 1
else:
        up = 0

if keyboard.getKeyDown(Key.A):
    isMoving = 1
    left = 1
else:
    left = 0

if keyboard.getKeyDown(Key.S):
    isMoving = 1
    down = 1
else:
    down = 0

if keyboard.getKeyDown(Key.D):
    isMoving = 1
    right = 1
else:
    right = 0

# Process movement
# Diagonals first...
if up == 1 and right == 1:
    vJoy[0].x = axis * 0.7
    vJoy[0].y = -axis * 0.7
elif up == 1 and left == 1:
    vJoy[0].x = -axis * 0.7
    vJoy[0].y = -axis * 0.7
elif down == 1 and left == 1:
    vJoy[0].x = -axis * 0.7
    vJoy[0].y = axis * 0.7
elif down == 1 and right == 1:
    vJoy[0].x = axis * 0.7
    vJoy[0].y = axis * 0.7
elif up == 1:
    vJoy[0].x = 0
    vJoy[0].y = -axis
elif left == 1:
    vJoy[0].x = -axis
    vJoy[0].y = 0
elif down == 1:
    vJoy[0].x = 0
    vJoy[0].y = axis
elif right == 1:
    vJoy[0].x = axis
    vJoy[0].y = 0
else:
    isMoving = 0
    vJoy[0].x = 0
    vJoy[0].y = 0

# Mouse look
if isMoving == 1:
    vJoy[0].z = -mouse.deltaX * mouseSmooth
    vJoy[0].ry = mouse.deltaY * mouseSmooth
    if mouseSmooth < mouseSens:
        mouseSmooth += 10
else:
    mouseSmooth = 0
    vJoy[0].z = 0
    vJoy[0].ry = 0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Erling Olsen