KGuiAddons 5.109.0
Properties | Signals | Public Slots | Public Member Functions | List of all members
KeySequenceRecorder

Record a QKeySequence by listening to key events in a window. More...

#include <KeySequenceRecorder>

Properties

QKeySequence currentKeySequence
 The recorded key sequence.
 
bool isRecording
 Whether key events are currently recorded.
 
bool modifierlessAllowed
 If key presses of "plain" keys without a modifier are considered to be a valid finished key combination.
 
bool modifierOnlyAllowed
 It makes it acceptable for the key sequence to be just a modifier (e.g.
 
bool multiKeyShortcutsAllowed
 Controls the amount of key combinations that are captured until recording stops and gotKeySequence is emitted.
 
QWindow * window
 The window in which the key events are happening that should be recorded.
 

Signals

void currentKeySequenceChanged ()
 
void gotKeySequence (const QKeySequence &keySequence)
 This signal is emitted when a key sequence has been recorded.
 
void modifierlessAllowedChanged ()
 
void modifierOnlyAllowedChanged ()
 
void multiKeyShortcutsAllowedChanged ()
 
void recordingChanged ()
 
void windowChanged ()
 

Public Slots

void cancelRecording ()
 Stops the recording session.
 

Public Member Functions

 KeySequenceRecorder (QWindow *window, QObject *parent=nullptr)
 Constructor.
 
QKeySequence currentKeySequence () const
 
bool isRecording () const
 
bool modifierlessAllowed () const
 
bool modifierOnlyAllowed () const
 
bool multiKeyShortcutsAllowed () const
 
void setCurrentKeySequence (const QKeySequence &sequence)
 
void setModifierlessAllowed (bool allowed)
 
void setModifierOnlyAllowed (bool allowed)
 
void setMultiKeyShortcutsAllowed (bool allowed)
 
void setWindow (QWindow *window)
 
void startRecording ()
 Start recording.
 
QWindow * window () const
 

Detailed Description

Record a QKeySequence by listening to key events in a window.

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. Either by using the keyboard-shortcuts-inhibit protocol on Wayland or grabbing the keyboard.

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

Since
5.77
See also
KKeySequenceWidget, KeySequenceItem

Property Documentation

◆ currentKeySequence

QKeySequence KeySequenceRecorder::currentKeySequence
readwrite

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

◆ isRecording

bool KeySequenceRecorder::isRecording
read

Whether key events are currently recorded.

◆ modifierlessAllowed

bool KeySequenceRecorder::modifierlessAllowed
readwrite

If key presses of "plain" keys without a modifier are considered to be a valid finished key combination.

Plain keys include letter and symbol keys and text editing keys (Return, Space, Tab, Backspace, Delete). Other keys like F1, Cursor keys, Insert, PageDown will always work.

By default this is false.

◆ modifierOnlyAllowed

bool KeySequenceRecorder::modifierOnlyAllowed
readwrite

It makes it acceptable for the key sequence to be just a modifier (e.g.

Shift or Control)

By default, if only a modifier is pressed and then released, the component will remain waiting for the sequence. When enabled, it will take the modifier key as the key sequence.

By default this is false.

◆ multiKeyShortcutsAllowed

bool KeySequenceRecorder::multiKeyShortcutsAllowed
readwrite

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.

See also
QKeySequence

◆ window

QWindow * KeySequenceRecorder::window
readwrite

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

Constructor & Destructor Documentation

◆ KeySequenceRecorder()

KeySequenceRecorder::KeySequenceRecorder ( QWindow *  window,
QObject *  parent = nullptr 
)
explicit

Constructor.

window The window whose key events will be recorded.
See also
window

Member Function Documentation

◆ cancelRecording

void KeySequenceRecorder::cancelRecording ( )
slot

Stops the recording session.

◆ gotKeySequence

void KeySequenceRecorder::gotKeySequence ( const QKeySequence &  keySequence)
signal

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.

◆ startRecording()

void KeySequenceRecorder::startRecording ( )

Start recording.

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