vtk python doesn't support get key PgUp/PgDn

Hi, I’m using `vtk==9.5.0` with python in PySide2. Below is my simple script that I try to catch user key press and do works. But when I type PgUp PgDn the GetKeySym return None . Just wanna know if vtk doesn’t support it at all or just in python?

import sys
from PySide2.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget
from vtkmodules.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
import vtkmodules.all as vtk


class VTKViewer(QMainWindow):
    """
    A PySide2 QMainWindow that embeds a VTK 3D viewer to display a point cloud.
    """
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setGeometry(100, 100, 900, 700) # x, y, width, height

        # Central widget and layout
        central_widget = QWidget()
        self.setCentralWidget(central_widget)
        layout = QVBoxLayout(central_widget)

        # Create the QVTKRenderWindowInteractor widget
        # This widget provides the VTK rendering context within a Qt application
        self.vtkWidget = QVTKRenderWindowInteractor(central_widget)
        layout.addWidget(self.vtkWidget)

        # Get the VTK renderer and render window from the interactor
        self.renderer = vtk.vtkRenderer()
        self.render_window = self.vtkWidget.GetRenderWindow()
        self.render_window.AddRenderer(self.renderer)
        self.renderer.SetBackground(0.1, 0.1, 0.9)  # Set background color

        self.interactor = self.render_window.GetInteractor()
        self.interactor_style = vtk.vtkInteractorStyleMultiTouchCamera()
        self.interactor.SetInteractorStyle(self.interactor_style)
        self.interactor.AddObserver(
            vtk.vtkCommand.KeyPressEvent, self._when_key_pressed
        )

        self.interactor.Initialize()

        camera = self.renderer.GetActiveCamera()
        camera.SetPosition(2.5, 2.5, 2.5)  # Example view from top-right-front
        camera.SetFocalPoint(0, 0, 0.2)  # Focus on the base
        camera.SetViewUp(0, 0, 1)  # Z-axis up
        self.render_window.Render()

    def _when_key_pressed(self, obj, event):
        key = self.interactor.GetKeySym()
        _ctrl_key = self.interactor.GetControlKey()
        _shift_key = self.interactor.GetShiftKey()
        _alt_key = self.interactor.GetAltKey()
        print(f"Key pressed: {key} (ctrl: {_ctrl_key}, shift: {_shift_key}, alt: {_alt_key})")


if __name__ == "__main__":
    app = QApplication([])
    viewer = VTKViewer()
    viewer.show()

    sys.exit(app.exec_())


I looked through the git history of QVTKRenderWindowInteractor.py to see what’s going on here.

It seems that when the keysym mappings were added to QVTKRenderWindowInteractor.py, these keys were skipped because there was uncertainty about how they were named.

I checked, and their names in Qt are PageUp and PageDown but their keysyms are actually Prior and Next.

So in QVTKRenderWindowInteractor.py at around line 720, you can change this:

    # Key.Key_Prior : 'Prior',
    # Key.Key_Next : 'Next',

to this:

    Key.Key_PageUp : 'Prior',
    Key.Key_PageDown: 'Next',

And then you can observe ‘Prior’ and ‘Next’ to see when those keys are pressed.

Thanks you. I can manage to make it works