Skip to content

Commit 64ff000

Browse files
authored
Add keydown callback option to Python visualizer (#38)
* Add keydown callback option to Python visualizer * Override existing keybinds
1 parent bdb8cfe commit 64ff000

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

python/cli/visualization/visualizer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ class VisualizerArgs:
215215

216216
# Callbacks
217217
customRenderCallback = None # Used to render custom OpenGL objects in user code
218+
customKeyDownCallbacks = {} # User callback is called when event.type == pygame.KEYDOWN and event.key == key
218219

219220
class Recorder:
220221
def __init__(self, recordPath, resolution):
@@ -398,7 +399,9 @@ def __processUserInput(self):
398399
if event.type == pygame.QUIT:
399400
self.shouldQuit = True
400401
elif event.type == pygame.KEYDOWN:
401-
if event.key == pygame.K_q: self.shouldQuit = True
402+
if event.key in self.args.customKeyDownCallbacks:
403+
self.args.customKeyDownCallbacks[event.key]()
404+
elif event.key == pygame.K_q: self.shouldQuit = True
402405
elif event.key == pygame.K_SPACE: self.shouldPause = not self.shouldPause
403406
elif event.key == pygame.K_c:
404407
self.cameraMode = self.cameraMode.next()

0 commit comments

Comments
 (0)