Home Download Gallery Documentation Developer

# Keyboard shortcut customization

Default shortcut bindings are described below. They can be redefined in your application and you can add new ones. See the keyboardAndMouse example for a practical illustration.

## Default keyboard shortcuts

This table lists the different `KeyboardAction` with their default shortcuts.

`KeyboardAction` | Key | Description | Associated function
DRAW_AXIS | A | Toggles the display of the world axis | `QGLViewer::toggleAxisIsDrawn()`
DRAW_GRID | G | Toggles the display of the XY grid | `QGLViewer::toggleGridIsDrawn()`
DISPLAY_FPS | F | Toggles the display of the frame rate | `QGLViewer::toggleFPSIsDisplayed()`
ENABLE_TEXT | ? | Toggles the display of all the text | `QGLViewer::toggleTextIsEnabled()`
STEREO | S | Toggles the stereo display | `QGLViewer::toggleStereoDisplay()`
HELP | H | Displays a help window | `QGLViewer::help()`
EXIT_VIEWER | Escape | Quits the application | `qApp->quit`
CAMERA_MODE | Space | Switches between the FLY and REVOLVE camera mode | `camera()->toggleCameraMode()`
ANIMATION | Return | Starts/stops the animation loop | `QGLViewer::toggleAnimation()`
SAVE_SCREENSHOT | Ctrl+S | Opens the save screenshot dialog box | `QGLViewer::saveSnapshot()`
FULL_SCREEN | Alt+Return | Toggles the full screen mode | `QGLViewer::toggleFullScreen()`
EDIT_CAMERA | C | Toggles the camera edition | `toggleCameraIsEdited()`
INCREASE_FLYSPEED DECREASE_FLYSPEED | + / - | Increases or decreases the camera fly speed. | `camera()->setFlySpeed()`
MOVE_CAMERA_LEFT MOVE_CAMERA_RIGHT MOVE_CAMERA_UP MOVE_CAMERA_DOWN | Left, right up and down arrow keys | Moves the camera, parallel to the screen. Displacement amplitude is proportional to `flySpeed()` | `camera()->frame()->translate(...)`
See `pathKey()` and `playPathKeyboardModifiers()` | F1...F12 | Plays/Pauses camera key frame path (if defined) Reset the path when Fx is quickly press twice. | `camera()->playPath(i)` `camera()->resetPath(i)`
See `pathKey()` and `addKeyFrameKeyboardModifiers()` | Alt+(F1...F12) | Defines a new camera key frame for path 1..12. Deletes the path when Fx is quickly press twice. | `camera()->addKeyFrameToPath(i)` `camera()->deletePath(i)`

Use `QGLViewer::setShortcut(Action, Key)` to redefine one of these (probably in your `init()` function). `Action` is defined by the `KeyboardAction` enum, described in the above table, while `Key` is provided as an `int` using Qt enumerated values. Setting `0` as the shortcut key disables the associated `KeyboardAction`:

    void Viewer::init()
    {
      // Press 'Q' to exit application
      setShortcut(EXIT_VIEWER, Qt::Key_Q);

      // Alt+M toggles camera mode
      setShortcut(CAMERA_MODE, Qt::ALT+Qt::Key_M);

      // The DISPLAY_FPS action is disabled
      setShortcut(DISPLAY_FPS, 0);
    }

You can retrieve the current shortcut with `shortcut(Action)`. Current bindings are always available in the help window "Keyboard" tab.

## Binding new keyboard actions

If you want to define a new keyboard shortcuts for one of your own methods, overload the `QGLViewer::keyPressEvent(QKeyEvent *e)` method:

    void Viewer::keyPressEvent(QKeyEvent *e)
      {
        switch (e->key())
        {
          case Qt::Key_R : myResetMethod(); updateGL(); break;
          // and so on...

          // Default calls the original method to handle standard keys
          default: QGLViewer::keyPressEvent(e);
        }
      }

You should then use `setKeyDescription()` to add a short description of your keyboard shortcut in the `help` window. See the keyboardAndMouse example for a practical illustration.

## Camera paths keyboard bindings

A `Camera` can have associated `KeyFrameInterpolator` that define paths and positions. The `F1...F12` keys (noted Fx below) are binded to the `Camera::keyFrameInterpolator()` of indexes 1..12 by default.

- `Alt+Fx` adds a new keyFrame to path x.
- `Fx` will then make the Camera play/pause the associated path (or will simply restore the saved position if only one keyFrame was defined for this path).

Quickly pressing `Fx` twice resets the interpolation:

- `Alt+Fx+Fx` deletes path x.
- `Fx+Fx` resets path x to its starting point.

Use these methods to modify the camera path keyboard shortcuts:

- `setPathKey(int key, int index)` (default are `F1...F12` for path 1..12),
- `setAddKeyFrameKeyboardModifiers(int buttonState)` (default is `Alt`) and
- `setPlayPathKeyboardModifiers(int buttonState)` (default is no modifier).

Last modified on Monday, November 13, 2017.