From 01401d32212a7cb15dbce95a74c2bb7c172e8a3f Mon Sep 17 00:00:00 2001 From: Tango Date: Sat, 28 Feb 2026 19:14:16 +0000 Subject: [PATCH] Big code rewrite, now using pynput for listening to user input. Updated README. --- OSCWalker.py | 57 ++++++++++++++++++++++++++-------------------------- README.md | 9 ++++----- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/OSCWalker.py b/OSCWalker.py index 5f0afa3..be87f89 100644 --- a/OSCWalker.py +++ b/OSCWalker.py @@ -1,10 +1,6 @@ from pythonosc.udp_client import SimpleUDPClient +from pynput import keyboard import time -import pygame -pygame.init() -screen = pygame.display.set_mode((200,200)) -running = True -clock = pygame.time.Clock() ip = "127.0.0.1" port = 9000 @@ -14,49 +10,54 @@ client = SimpleUDPClient(ip, port) # Create client right = True left = True -movingAmount = 40 # Change for moving duration +movingAmount = 50 # Change for moving duration moving = 0 steps = 0 +# Main movement code +def on_press(key): -# Movement -while running: + # What am I doing... + global steps, left, right, moving - for event in pygame.event.get(): - if event.type == pygame.QUIT: - running = False - - keys=pygame.key.get_pressed() - screen.fill("orange") - - #Code for alternating steps - - if keys[pygame.K_F13] and left == True: + # If left step taken and right step was taken before + if key == keyboard.Key.f13 and left == True: + global steps steps += 1 moving = movingAmount left = False client.send_message("/input/MoveForward", 1) # Move forward right = True print(steps) - - if keys[pygame.K_F14] and right == True: + # If right step taken and left step was taken before + if key == keyboard.Key.f14 and right == True: steps += 1 moving = movingAmount - right = False - client.send_message("/input/MoveForward", 1) # Move forward left = True + client.send_message("/input/MoveForward", 1) # Move forward + right = False print(steps) - #Constant move forward code with grace period to allow non-stop steps. +# I think this is right... it's working so far... - if moving == 0: - client.send_message("/input/MoveForward", 0) - else: +listener = keyboard.Listener( + on_press=on_press, +) + +#Start listening for keyboard inputs... I think... This is why you don't copy code kids +listener.start() + + +# Loop for moving grace period, essentially a timer before actually stopping movement +while True: + if moving > 0: moving -= 1 - pygame.display.flip() + if moving == 0: + client.send_message("/input/MoveForward", 0) + print("Stopped moving") - clock.tick(100) \ No newline at end of file + time.sleep(0.01) \ No newline at end of file diff --git a/README.md b/README.md index 4476272..f455022 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Extremely simple program that allows to track inputs from a Wii Balance Board in - VRChat (It was kind of made for... specifically VRChat)
- Bluetooth
-- Uses Pygame (pip install pygame)
+- Uses Pynput (pip install pynput)
- Uses python-osc (pip install python-osc) - [Uses Python](https://www.python.org/)
- [Uses WiiBalanceWalker by Shachar Liberman](https://github.com/lshachar/WiiBalanceWalker)
@@ -29,14 +29,13 @@ Extremely simple program that allows to track inputs from a Wii Balance Board in ### Windows +If there is a release, download and use that, otherwise: + - Download the zip file by pressing the big green "Code" button, then "Download ZIP". - Extract the folder and open it. - While inside the folder, right click empty space and click "Open in Terminal" - Type and run "python OSCWalker.py" -**You may want to run pygame while within VSCode/Codium in order to view terminal logs** - ## Troubleshoot -- Ensure that pygame is installed. -- Ensure that the pygame window is focused. + - Ensure OSC is enabled in the VRChat quick menu. \ No newline at end of file