Created
October 9, 2020 10:26
-
-
Save Theaninova/5889740cffd3de5ec0cbf5cfb3800c4e to your computer and use it in GitHub Desktop.
Joystick Gremlin Stepped Axis-to-Button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inspired/Adapted from original WhiteMagic | |
# https://gist.github.com/WhiteMagic/ff636574b45a12480fd0bd6f1a92740e | |
import time | |
import gremlin | |
from gremlin.user_plugin import * | |
mode = ModeVariable("Mode", "The mode in which to use this mapping") | |
axis = PhysicalInputVariable( | |
"Input axis", | |
"Input axis", | |
[gremlin.common.InputType.JoystickAxis] | |
) | |
axis_max_out = VirtualInputVariable( | |
"Positive Axis button", | |
"Positive Axis button", | |
[gremlin.common.InputType.JoystickButton] | |
) | |
axis_min_out = VirtualInputVariable( | |
"Negative Axis button", | |
"Negative Axis button", | |
[gremlin.common.InputType.JoystickButton] | |
) | |
axis_center_out = VirtualInputVariable( | |
"Center Axis button", | |
"Center Axis button", | |
[gremlin.common.InputType.JoystickButton] | |
) | |
threshold = FloatVariable( | |
"Threshold until max/min applies", | |
"Amount of change per step", | |
0.4, | |
0.0, | |
1.0 | |
) | |
# Decorators for the two physical axes | |
decorator = axis.create_decorator(mode.value) | |
# Axis max macro | |
max_axis_macro = gremlin.macro.Macro() | |
max_axis_macro.exclusive = True | |
max_axis_macro.add_action(gremlin.macro.VJoyAction( | |
axis_max_out.vjoy_id, | |
gremlin.common.InputType.JoystickButton, | |
axis_max_out.input_id, | |
True | |
)) | |
max_axis_macro.add_action(gremlin.macro.PauseAction(0.05)) | |
max_axis_macro.add_action(gremlin.macro.VJoyAction( | |
axis_max_out.vjoy_id, | |
gremlin.common.InputType.JoystickButton, | |
axis_max_out.input_id, | |
False | |
)) | |
# Axis min macro | |
min_axis_macro = gremlin.macro.Macro() | |
min_axis_macro.exclusive = True | |
min_axis_macro.add_action(gremlin.macro.VJoyAction( | |
axis_min_out.vjoy_id, | |
gremlin.common.InputType.JoystickButton, | |
axis_min_out.input_id, | |
True | |
)) | |
min_axis_macro.add_action(gremlin.macro.PauseAction(0.05)) | |
min_axis_macro.add_action(gremlin.macro.VJoyAction( | |
axis_min_out.vjoy_id, | |
gremlin.common.InputType.JoystickButton, | |
axis_min_out.input_id, | |
False | |
)) | |
# Axis center macro | |
center_axis_macro = gremlin.macro.Macro() | |
center_axis_macro.exclusive = True | |
center_axis_macro.add_action(gremlin.macro.VJoyAction( | |
axis_center_out.vjoy_id, | |
gremlin.common.InputType.JoystickButton, | |
axis_center_out.input_id, | |
True | |
)) | |
center_axis_macro.add_action(gremlin.macro.PauseAction(0.05)) | |
center_axis_macro.add_action(gremlin.macro.VJoyAction( | |
axis_center_out.vjoy_id, | |
gremlin.common.InputType.JoystickButton, | |
axis_center_out.input_id, | |
False | |
)) | |
positive_threshold = threshold.value | |
negative_threshold = -threshold.value | |
g_last_value = 1 | |
@decorator.axis(axis.input_id) | |
def axis1(event, vjoy): | |
global g_last_value | |
if event.value > positive_threshold and g_last_value != 2: | |
g_last_value = 2 | |
gremlin.macro.MacroManager().queue_macro(max_axis_macro) | |
elif event.value < negative_threshold and g_last_value != 0: | |
g_last_value = 0 | |
gremlin.macro.MacroManager().queue_macro(min_axis_macro) | |
elif negative_threshold <= event.value <= positive_threshold and g_last_value != 1: | |
g_last_value = 1 | |
gremlin.macro.MacroManager().queue_macro(center_axis_macro) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment