Skip to content

Commit

Permalink
Add keydown callback option to Python visualizer (#38)
Browse files Browse the repository at this point in the history
* Add keydown callback option to Python visualizer

* Override existing keybinds
  • Loading branch information
kaatrasa authored May 17, 2024
1 parent bdb8cfe commit 64ff000
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python/cli/visualization/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 64ff000

Please sign in to comment.