I want to emulate a mouse click on the Qt virtual keyboard key. I have a QML application on Qt6 with a virtual keyboard.
I found the following code on the qtwebdriver GitHub repository:
void Quick2ViewCmdExecutor::ClickElement(const ElementId& element, Error** error) {
QQuickWindow* view = getView(view_id_, error);
if (NULL == view)
return;
QQuickItem* pItem = getElement(element, error);
if (NULL == pItem)
return;
if (!pItem->isVisible()) {
*error = new Error(kElementNotVisible);
return;
}
session_->logger().Log(kFineLogLevel, "Click on:");
session_->logger().Log(kFineLogLevel, pItem->objectName().toStdString());
QPointF scenePoint = pItem->mapToScene(QPointF(pItem->width()/2.0,pItem->height()/2.0));
QRectF sceneRect(QPointF(0,0), view->size());
if (!sceneRect.contains(scenePoint)) {
*error = new Error(kMoveTargetOutOfBounds);
return;
}
QMouseEvent *pressEvent = new QMouseEvent(QEvent::MouseButtonPress,
scenePoint,
Qt::LeftButton,
Qt::LeftButton,
Qt::NoModifier);
QMouseEvent *releaseEvent = new QMouseEvent(QEvent::MouseButtonRelease,
scenePoint,
Qt::LeftButton,
Qt::LeftButton,
Qt::NoModifier);
QGuiApplication::postEvent(view, pressEvent);
QGuiApplication::postEvent(view, releaseEvent);
QGuiApplication::processEvents();
}
It appears that the press event works correctly and the key is pressed, but the release signal is not emitted. This code works well with other quick elements except for the Keyboard. The issue might be related to the usage of MultiPointTouchArea in Keyboard.qml.