Skip to content

Instantly share code, notes, and snippets.

@IslandJohn
Last active December 24, 2022 14:43
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IslandJohn/06589d5dec3c278dcd75f207cf42d099 to your computer and use it in GitHub Desktop.
Save IslandJohn/06589d5dec3c278dcd75f207cf42d099 to your computer and use it in GitHub Desktop.
Joystick Gremlin plugin to remap the OFF/ON/ON states of a physical toggle switch to 3 virtual buttons, simulating an ON/ON/ON toggle switch.
import gremlin
from gremlin.user_plugin import *
mode = ModeVariable(
"Mode",
"The mode to use for this instance"
)
joy_1 = PhysicalInputVariable(
"Physical ON 1",
"Physical ON 1",
[gremlin.common.InputType.JoystickButton]
)
joy_2 = PhysicalInputVariable(
"Physical ON 2",
"Physical ON 2",
[gremlin.common.InputType.JoystickButton]
)
vjoy_1 = VirtualInputVariable(
"Virtual ON 1 (P-OFF)",
"Virtual ON 1 (Physical OFF)",
[gremlin.common.InputType.JoystickButton]
)
vjoy_2 = VirtualInputVariable(
"Virtual ON 2 (P-ON1)",
"Virtual ON 2 (Physical ON 1)",
[gremlin.common.InputType.JoystickButton]
)
vjoy_3 = VirtualInputVariable(
"Virtual ON 3 (P-ON2)",
"Virtual ON 3 (Physical ON 2)",
[gremlin.common.InputType.JoystickButton]
)
decorator_1 = joy_1.create_decorator(mode.value)
decorator_2 = joy_2.create_decorator(mode.value)
def change_state(joy, vjoy):
global joy_1, joy_2, vjoy_1, vjoy_2, vjoy_3
j1 = joy[joy_1.value["device_id"]].button(joy_1.value["input_id"])
j2 = joy[joy_2.value["device_id"]].button(joy_2.value["input_id"])
v1 = vjoy[vjoy_1.value["device_id"]].button(vjoy_1.value["input_id"])
v2 = vjoy[vjoy_2.value["device_id"]].button(vjoy_2.value["input_id"])
v3 = vjoy[vjoy_3.value["device_id"]].button(vjoy_3.value["input_id"])
v1.is_pressed = not j1.is_pressed and not j2.is_pressed
v2.is_pressed = j1.is_pressed
v3.is_pressed = j2.is_pressed
@decorator_1.button(joy_1.input_id)
@decorator_2.button(joy_2.input_id)
def joy_event(event, joy, vjoy):
change_state(joy, vjoy)
if joy_1.value is not None:
joy_init = gremlin.input_devices.JoystickPlugin.joystick
vjoy_init = gremlin.input_devices.VJoyPlugin.vjoy
change_state(joy_init, vjoy_init)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment