2

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,

Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47
Simon
  • 1,522
  • 2
  • 12
  • 24
  • 4
    I think for `CTRL+L` you should right it like: `new QKeyEvent ( QEvent::KeyPress, Qt::Key_L, Qt::ControlModifier);`, i.e. only a single key event should be sent with `L` key and `Ctrl` modifier. – vahancho Feb 05 '18 at 10:06
  • 1
    It's about _key combination_ rather than sequence .. I got it after @vahancho commented. – Mohammad Kanan Feb 05 '18 at 10:24

0 Answers0