How to post Key Combination events in Qt like CTRL-L

695 Views Asked by At

I know how to post single key event

    QKeyEvent *poKeyEvent = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
    QCoreApplication::postEvent (this, poKeyEvent);

Now I want to post a combination of key events for example QKeySequence(tr("Ctrl+L"));

Is this a proper way of posting a key sequence events?

    // First key event - 'Ctrl'
    QKeyEvent *poFirstKeyEvent = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Control, Qt::NoModifier);
    QCoreApplication::postEvent (this, poFirstKeyEvent);

    // Second key event - 'L'    
    QKeyEvent *poSecondtKeyEvent = new QKeyEvent ( QEvent::KeyPress, Qt::Key_L, Qt::NoModifier);
    QCoreApplication::postEvent (this, poSecondtKeyEvent);

Any other way to implement this?

Thanks,

0

There are 0 best solutions below