Created
May 7, 2022 14:43
-
-
Save Naraenda/68336c534444b7ede0b496a20bded33b to your computer and use it in GitHub Desktop.
LTEK Gamepad to VRChat OSC
This file contains hidden or 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
# You need to install the 'pygame' and 'pythonosc' libraries | |
# Since the LTEK is a gamepad, VRChat will read its button presses as game inputs which we do not want | |
# A solution to that is to use https://github.com/ViGEm/HidHide to hide the controller input to the VRChat process. | |
import collections, pygame | |
from pythonosc import udp_client | |
# These are the VRC avatar parameters it'll send the events to | |
OSC_MAP = { | |
0: 'DDR_LEFT', | |
1: 'DDR_RIGHT', | |
2: 'DDR_UP', | |
3: 'DDR_DOWN', | |
} | |
def main(): | |
# Clear screen and disable cursor | |
print('\033[?25l\033[2J', end="") | |
# Set up OSC client | |
osc = udp_client.SimpleUDPClient('127.0.0.1', 9000) | |
# Start pygame shizzle | |
pygame.init() | |
clock:pygame.time.Clock = pygame.time.Clock() | |
for i in range(0, pygame.joystick.get_count()): | |
controller = pygame.joystick.Joystick(i) | |
if 'L-TEK' not in controller.get_name(): | |
continue | |
controller.init() | |
break | |
# Button map | |
buttons = collections.defaultdict(lambda: False) | |
while True: | |
clock.tick(30) | |
for event in pygame.event.get(): | |
# Handle DDR buttons! | |
if event.type == pygame.JOYBUTTONUP: | |
buttons[event.button] = False | |
if event.button in OSC_MAP: | |
osc.send_message(f'/avatar/parameters/{OSC_MAP[event.button]}', 0) | |
if event.type == pygame.JOYBUTTONDOWN: | |
buttons[event.button] = True | |
if event.button in OSC_MAP: | |
osc.send_message(f'/avatar/parameters/{OSC_MAP[event.button]}', 1) | |
# create cool preview | |
preview = list(' \n * \n ') | |
if buttons[0]: | |
preview[4] = '<' | |
if buttons[1]: | |
preview[6] = '>' | |
if buttons[2]: | |
preview[1] = '^' | |
if buttons[3]: | |
preview[9] = 'V' | |
# Print DDR preview | |
print('\033[1;1H' + ''.join(preview)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment