Skip to content

Instantly share code, notes, and snippets.

@IslandJohn
Created August 10, 2020 02:40
Show Gist options
  • Select an option

  • Save IslandJohn/907592f0250a20c65733ec4440a2eaa4 to your computer and use it in GitHub Desktop.

Select an option

Save IslandJohn/907592f0250a20c65733ec4440a2eaa4 to your computer and use it in GitHub Desktop.
Joystick Gremlin plugin to remap the OFF/ON states of a physical toggle switch to 2 virtual buttons, simulating an 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",
"Physical ON",
[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-ON)",
"Virtual ON 2 (Physical ON)",
[gremlin.common.InputType.JoystickButton]
)
decorator_1 = joy_1.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"])
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"])
v1.is_pressed = not j1.is_pressed
v2.is_pressed = j1.is_pressed
@decorator_1.button(joy_1.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)
@guilhermelimak

Copy link
Copy Markdown

bro this is great thanks for posting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment