From 64ff00087ce102d6bcd705b450c0e70cd787cb86 Mon Sep 17 00:00:00 2001 From: Valtteri Kaatrasalo <46484036+kaatrasa@users.noreply.github.com> Date: Fri, 17 May 2024 13:58:28 +0300 Subject: [PATCH] Add keydown callback option to Python visualizer (#38) * Add keydown callback option to Python visualizer * Override existing keybinds --- python/cli/visualization/visualizer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/cli/visualization/visualizer.py b/python/cli/visualization/visualizer.py index 6a0af43..eccc8f2 100644 --- a/python/cli/visualization/visualizer.py +++ b/python/cli/visualization/visualizer.py @@ -215,6 +215,7 @@ class VisualizerArgs: # Callbacks customRenderCallback = None # Used to render custom OpenGL objects in user code + customKeyDownCallbacks = {} # User callback is called when event.type == pygame.KEYDOWN and event.key == key class Recorder: def __init__(self, recordPath, resolution): @@ -398,7 +399,9 @@ def __processUserInput(self): if event.type == pygame.QUIT: self.shouldQuit = True elif event.type == pygame.KEYDOWN: - if event.key == pygame.K_q: self.shouldQuit = True + if event.key in self.args.customKeyDownCallbacks: + self.args.customKeyDownCallbacks[event.key]() + elif event.key == pygame.K_q: self.shouldQuit = True elif event.key == pygame.K_SPACE: self.shouldPause = not self.shouldPause elif event.key == pygame.K_c: self.cameraMode = self.cameraMode.next()