diff --git a/declarativeplugin/qml/RemoteKeyboard.qml b/declarativeplugin/qml/RemoteKeyboard.qml index 9aecd6704..34eec8b88 100644 --- a/declarativeplugin/qml/RemoteKeyboard.qml +++ b/declarativeplugin/qml/RemoteKeyboard.qml @@ -79,20 +79,8 @@ TextField { function sendEvent(event) { if (remoteKeyboard) { var transEvent = JSON.parse(JSON.stringify(event)); // transform to anonymous object - if (transEvent.modifiers & Qt.ControlModifier) { - // special handling for ctrl+c/v/x/a, for which only 'key' gets - // set, but no visible 'text', which is expected by the remoteKeyboard - // wire-format: - if (transEvent.key === Qt.Key_C) - transEvent.text = 'c'; - if (transEvent.key === Qt.Key_V) - transEvent.text = 'v'; - if (transEvent.key === Qt.Key_A) - transEvent.text = 'a'; - if (transEvent.key === Qt.Key_X) - transEvent.text = 'x'; - } remoteKeyboard.sendQKeyEvent(transEvent); + event.accepted = true } } diff --git a/plugins/remotekeyboard/remotekeyboardplugin.cpp b/plugins/remotekeyboard/remotekeyboardplugin.cpp index 5a449bf6e..f8ad748c5 100644 --- a/plugins/remotekeyboard/remotekeyboardplugin.cpp +++ b/plugins/remotekeyboard/remotekeyboardplugin.cpp @@ -8,6 +8,7 @@ #include "plugin_remotekeyboard_debug.h" #include #include +#include #include #include @@ -100,11 +101,23 @@ void RemoteKeyboardPlugin::sendKeyPress(const QString &key, int specialKey, bool void RemoteKeyboardPlugin::sendQKeyEvent(const QVariantMap &keyEvent, bool sendAck) const { - if (!keyEvent.contains(QStringLiteral("key"))) + if (!keyEvent.contains(QStringLiteral("key"))) { return; - int k = translateQtKey(keyEvent.value(QStringLiteral("key")).toInt()); + } + const int key = keyEvent.value(QStringLiteral("key")).toInt(); + int k = translateQtKey(key); int modifiers = keyEvent.value(QStringLiteral("modifiers")).toInt(); - sendKeyPress(keyEvent.value(QStringLiteral("text")).toString(), + + // Qt will be calling xkb_state_key_get_utf8 to create this string. + // As documented, it will be giving us weird strings with Ctrl combinations: + // https://xkbcommon.org/doc/current/group__keysyms.html + // Instead, just use QKeySequence to tell us which key that is and move on + QString text = keyEvent.value(QStringLiteral("text")).toString(); + if (!text.isEmpty() && !text[0].isLetterOrNumber()) { + text = QKeySequence(key).toString().toLower(); + } + + sendKeyPress(text, k, modifiers & Qt::ShiftModifier, modifiers & Qt::ControlModifier,