File indexing completed on 2024-11-17 04:55:13
0001 /* 0002 SPDX-FileCopyrightText: 2022 Aditya Mehra <aix.m@outlook.com> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #include <QCoreApplication> 0007 #include <QGuiApplication> 0008 #include <QKeyEvent> 0009 #include <QQuickItem> 0010 #include "virtualKeypress.h" 0011 0012 VirtualKeyPress::VirtualKeyPress() 0013 { 0014 } 0015 0016 VirtualKeyPress::~VirtualKeyPress() 0017 { 0018 } 0019 0020 void VirtualKeyPress::emitKey(QString stringkey) 0021 { 0022 qDebug() << "inEmitKey:" << stringkey; 0023 QKeySequence seq = QKeySequence(stringkey); 0024 qDebug() << seq.count(); 0025 uint keyCode = seq[0].toCombined(); 0026 Qt::Key key = Qt::Key(keyCode); 0027 QQuickItem* receiver = qobject_cast<QQuickItem*>(QGuiApplication::focusObject()); 0028 if(!receiver) { 0029 return; 0030 } 0031 QKeyEvent pressEvent = QKeyEvent(QEvent::KeyPress, key, Qt::NoModifier, stringkey, false, 1); 0032 QKeyEvent releaseEvent = QKeyEvent(QEvent::KeyRelease, key, Qt::NoModifier, stringkey, false, 1); 0033 QGuiApplication::sendEvent(receiver, &pressEvent); 0034 QGuiApplication::sendEvent(receiver, &releaseEvent); 0035 }