Pages
API Documentation
On this page

KKeySequenceRecorder Class

Record a QKeySequence by listening to key events in a window. This class was introduced in Qt 6.0. More...

  • Header: #include <KKeySequenceRecorder>
  • Since: Qt 6.0
  • CMake: find_package(KF6 REQUIRED COMPONENTS GuiAddons)
    target_link_libraries(mytarget PRIVATE KF6::GuiAddons)
  • Inherits: QObject

List of all members, including inherited members
Deprecated members

Public Types

Properties

Public Functions

Public Slots

Signals

Detailed Description

After calling startRecording key events in the set window will be captured until a valid QKeySequence has been recorded and gotKeySequence is emitted. See multiKeyShortcutsAllowed and modifierlessAllowed for what constitutes a valid key sequence.

During recording any shortcuts are inhibited and cannot be triggered by grabbing the keyboard.

For graphical elements that record key sequences and can optionally perform conflict checking against existing shortcuts see KKeySequenceWidget and KeySequenceItem.

Porting from KF5 to KF6:

The class KeySequenceRecorder was renamed to KKeySequenceRecorder.

See also KKeySequenceWidget, KeySequenceItem

Member Type Documentation

enum KKeySequenceRecorder::Pattern

flags KKeySequenceRecorder::Patterns

The Pattern type specifies what components the recorded shortcut must have, e.g. modifiers or just a key.

Constant Value Description
KKeySequenceRecorder::Modifier 0x1 The recorded shortcut must contain one or more modifier keys (Meta, Shift, Ctrl, or Alt).
KKeySequenceRecorder::Key 0x2 The recorded shortcut must contain only one regular key, e.g. "A".
KKeySequenceRecorder::ModifierAndKey 0x4 The recorded shortcut must contain one or more modifier keys followed by a regular key, e.g. Meta+A. Note: with this pattern, special keys like "Insert" without any pressed modifier will be captured too. Please do not rely on this behavior and instead use Key | ModifierAndKey explicitly. The future versions of KKeySequenceRecorder are expected not to record special keys in the ModifierAndKey mode.

The Patterns type is a typedef for QFlags<Pattern>. It stores an OR combination of Pattern values.

Property Documentation

currentKeySequence : QKeySequence

The recorded key sequence. After construction this is empty.

During recording it is continuously updated with the newest user input.

After recording it contains the last recorded QKeySequence

Access functions:

  • QKeySequence currentKeySequence() const
  • void setCurrentKeySequence(const QKeySequence &sequence)

Notifier signal:

  • void currentKeySequenceChanged()

[read-only] isRecording : bool

Whether key events are currently recorded

Access functions:

  • bool isRecording() const

Notifier signal:

  • void recordingChanged()

multiKeyShortcutsAllowed : bool

Controls the amount of key combinations that are captured until recording stops and gotKeySequence is emitted. By default this is true and "Emacs-style" key sequences are recorded. Recording does not stop until four valid key combination have been recorded. Afterwards currentKeySequence().count() will be 4.

Otherwise only one key combination is recorded before gotKeySequence is emitted with a QKeySequence with a count() of 1.

Access functions:

  • bool multiKeyShortcutsAllowed() const
  • void setMultiKeyShortcutsAllowed(bool allowed)

Notifier signal:

  • void multiKeyShortcutsAllowedChanged()

See also QKeySequence

[since 6.12] patterns : Patterns

Specifies what components the recorded shortcut must have, for example whether the shortcut must contain only modifier keys (Modifier) or modifiers keys and a normal key (ModifierAndKey).

The patterns property can contain one or more recording patterns. For example, if the recorder accepts both normal and modifier only shortcuts, e.g. Modifier | ModifierAndKey.

By default this is ModifierAndKey.

This property was introduced in Qt 6.12.

Access functions:

  • KKeySequenceRecorder::Patterns patterns() const
  • void setPatterns(KKeySequenceRecorder::Patterns patterns)

Notifier signal:

  • void patternsChanged()

window : QWindow*

The window in which the key events are happening that should be recorded

Access functions:

  • QWindow *window() const
  • void setWindow(QWindow *window)

Notifier signal:

  • void windowChanged()

Member Function Documentation

[explicit] KKeySequenceRecorder::KKeySequenceRecorder(QWindow *window, QObject *parent = nullptr)

Constructor.

window The window whose key events will be recorded.

See also window

[slot] void KKeySequenceRecorder::cancelRecording()

Stops the recording session

[signal] void KKeySequenceRecorder::gotKeySequence(const QKeySequence &keySequence)

This signal is emitted when a key sequence has been recorded.

Compared to currentKeySequenceChanged and currentKeySequence this is signal is not emitted continuously during recording but only after recording has finished.

[invokable] void KKeySequenceRecorder::startRecording()

Start recording. Calling startRecording when window() is nullptr has no effect.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.