发送按键事件到当前聚焦的窗体。
1.获取当前聚焦的QWidget
1 | QWidget *receiver = QApplication::focusWidget(); |
2.装载press与release事件
- key为按键键值(整型);
- value为按键实际值(QString).
1
2QKeyEvent keyPress(QEvent::KeyPress, key, Qt::NoModifier, value);
QKeyEvent keyRelease(QEvent::KeyRelease, key, Qt::NoModifier, value);
3.发送按键事件
1 | QApplication::sendEvent(receiver, &keyPress); |