Advertisement
Guest User

8W-to-4W hat

a guest
Feb 26th, 2022
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.33 KB | None | 0 0
  1. import gremlin
  2. from gremlin.user_plugin import *
  3.  
  4. active_mode = ModeVariable(
  5.         "Mode",
  6.         "Mode in which buttons will be asserted"
  7. )
  8. btn_1_in = PhysicalInputVariable(
  9.         "Button Up In",
  10.         "Button which is mapped to the up direction of the hat.",
  11.         [gremlin.common.InputType.JoystickButton]
  12. )
  13. btn_2_in = PhysicalInputVariable(
  14.         "Button Right In",
  15.         "Button which is mapped to the right direction of the hat.",
  16.         [gremlin.common.InputType.JoystickButton]
  17. )
  18. btn_3_in = PhysicalInputVariable(
  19.         "Button Down In",
  20.         "Button which is mapped to the down direction of the hat.",
  21.         [gremlin.common.InputType.JoystickButton]
  22. )
  23. btn_4_in = PhysicalInputVariable(
  24.         "Button Left In",
  25.         "Button which is mapped to the left direction of the hat.",
  26.         [gremlin.common.InputType.JoystickButton]
  27. )
  28. btn_5_in = PhysicalInputVariable(
  29.         "Button Depress In",
  30.         "Button which is mapped to the depress direction of the hat.",
  31.         [gremlin.common.InputType.JoystickButton]
  32. )
  33. btn_1_out = VirtualInputVariable(
  34.         "Button Up Out",
  35.         "Button which will be mapped to the up direction of the hat.",
  36.         [gremlin.common.InputType.JoystickButton]
  37. )
  38. btn_2_out = VirtualInputVariable(
  39.         "Button Right Out",
  40.         "Button which will be mapped to the right direction of the hat.",
  41.         [gremlin.common.InputType.JoystickButton]
  42. )
  43. btn_3_out = VirtualInputVariable(
  44.         "Button Down Out",
  45.         "Button which will be mapped to the down direction of the hat.",
  46.         [gremlin.common.InputType.JoystickButton]
  47. )
  48. btn_4_out = VirtualInputVariable(
  49.         "Button Left Out",
  50.         "Button which will be mapped to the left direction of the hat.",
  51.         [gremlin.common.InputType.JoystickButton]
  52. )
  53. btn_5_out = VirtualInputVariable(
  54.         "Button Depress Out",
  55.         "Button which will be mapped to the left direction of the hat.",
  56.         [gremlin.common.InputType.JoystickButton]
  57. )
  58.  
  59. joystick_decorator = btn_1_in.create_decorator(active_mode.value)
  60. button_pressed = False
  61.  
  62. @joystick_decorator.button(btn_1_in.input_id)
  63. def button_1(event, joy, vjoy):
  64.     global button_pressed
  65.     if event.is_pressed and not button_pressed:
  66.         vjoy[btn_1_out.value["device_id"]].button(btn_1_out.value["input_id"]).is_pressed = True
  67.         button_pressed = True
  68.     elif vjoy[btn_1_out.value["device_id"]].button(btn_1_out.value["input_id"]).is_pressed:
  69.         vjoy[btn_1_out.value["device_id"]].button(btn_1_out.value["input_id"]).is_pressed = False
  70.         button_pressed = False
  71.         button_2(joy[btn_2_in.value["device_id"]].button(btn_2_in.value["input_id"]), joy, vjoy)
  72.         if not button_pressed:
  73.             button_4(joy[btn_4_in.value["device_id"]].button(btn_4_in.value["input_id"]), joy, vjoy)
  74.    
  75. @joystick_decorator.button(btn_2_in.input_id)
  76. def button_2(event, joy, vjoy):
  77.     global button_pressed
  78.     if event.is_pressed and not button_pressed:
  79.         vjoy[btn_2_out.value["device_id"]].button(btn_2_out.value["input_id"]).is_pressed = True
  80.         button_pressed = True
  81.     elif vjoy[btn_2_out.value["device_id"]].button(btn_2_out.value["input_id"]).is_pressed:
  82.         vjoy[btn_2_out.value["device_id"]].button(btn_2_out.value["input_id"]).is_pressed = False
  83.         button_pressed = False
  84.         button_1(joy[btn_1_in.value["device_id"]].button(btn_1_in.value["input_id"]), joy, vjoy)
  85.         if not button_pressed:
  86.             button_3(joy[btn_3_in.value["device_id"]].button(btn_3_in.value["input_id"]), joy, vjoy)
  87.    
  88. @joystick_decorator.button(btn_3_in.input_id)
  89. def button_3(event, joy, vjoy):
  90.     global button_pressed
  91.     if event.is_pressed and not button_pressed:
  92.         vjoy[btn_3_out.value["device_id"]].button(btn_3_out.value["input_id"]).is_pressed = True
  93.         button_pressed = True
  94.     elif vjoy[btn_3_out.value["device_id"]].button(btn_3_out.value["input_id"]).is_pressed:
  95.         vjoy[btn_3_out.value["device_id"]].button(btn_3_out.value["input_id"]).is_pressed = False
  96.         button_pressed = False
  97.         button_2(joy[btn_2_in.value["device_id"]].button(btn_2_in.value["input_id"]), joy, vjoy)
  98.         if not button_pressed:
  99.             button_4(joy[btn_4_in.value["device_id"]].button(btn_4_in.value["input_id"]), joy, vjoy)
  100.    
  101. @joystick_decorator.button(btn_4_in.input_id)
  102. def button_4(event, joy, vjoy):
  103.     global button_pressed
  104.     if event.is_pressed and not button_pressed:
  105.         vjoy[btn_4_out.value["device_id"]].button(btn_4_out.value["input_id"]).is_pressed = True
  106.         button_pressed = True
  107.     elif vjoy[btn_4_out.value["device_id"]].button(btn_4_out.value["input_id"]).is_pressed:
  108.         vjoy[btn_4_out.value["device_id"]].button(btn_4_out.value["input_id"]).is_pressed = False
  109.         button_pressed = False
  110.         button_1(joy[btn_1_in.value["device_id"]].button(btn_1_in.value["input_id"]), joy, vjoy)
  111.         if not button_pressed:
  112.             button_3(joy[btn_3_in.value["device_id"]].button(btn_3_in.value["input_id"]), joy, vjoy)
  113.    
  114. @joystick_decorator.button(btn_5_in.input_id)
  115. def button_5(event, joy, vjoy):
  116.     if event.is_pressed and not button_pressed:
  117.         vjoy[btn_5_out.value["device_id"]].button(btn_5_out.value["input_id"]).is_pressed = True
  118.     else:
  119.         vjoy[btn_5_out.value["device_id"]].button(btn_5_out.value["input_id"]).is_pressed = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement