From 788c8ba53d68e3b87b95f1168472e900032005a3 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sat, 17 Jul 2021 10:23:08 -0400 Subject: [PATCH] Fix using modifier keys * Fix error in regex that prevented use of modifier keys in general. * Added '#' modifier to press the "Meta" button. This correlates to the Windows key on Windows and Command key on macOS. * Fix #6695 - send proper modifier keys based on documentation --- src/autotype/AutoType.cpp | 5 ++++- src/autotype/mac/AutoTypeMac.cpp | 6 ++++++ src/autotype/windows/AutoTypeWindows.cpp | 6 ++++++ src/gui/osutils/macutils/MacUtils.cpp | 4 ++++ src/gui/osutils/winutils/WinUtils.cpp | 2 ++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/autotype/AutoType.cpp b/src/autotype/AutoType.cpp index 8b9089d6b7..daed6a1ea2 100644 --- a/src/autotype/AutoType.cpp +++ b/src/autotype/AutoType.cpp @@ -553,7 +553,7 @@ AutoType::parseSequence(const QString& entrySequence, const Entry* entry, QStrin // Group 3 = inner placeholder (allows nested placeholders) // Group 4 = repeat (opt) // Group 5 = character - QRegularExpression regex("([+%^]*)({((?>[^{}]+?|(?2))+?)(?:\\s+(\\d+))?})|(.)"); + QRegularExpression regex("([+%^#]*)(?:({((?>[^{}]+?|(?2))+?)(?:\\s+(\\d+))?})|(.))"); auto results = regex.globalMatch(sequence); while (results.hasNext()) { auto match = results.next(); @@ -569,6 +569,9 @@ AutoType::parseSequence(const QString& entrySequence, const Entry* entry, QStrin if (match.captured(1).contains('%')) { modifiers |= Qt::AltModifier; } + if (match.captured(1).contains('#')) { + modifiers |= Qt::MetaModifier; + } const auto fullPlaceholder = match.captured(2); auto placeholder = match.captured(3).toLower(); diff --git a/src/autotype/mac/AutoTypeMac.cpp b/src/autotype/mac/AutoTypeMac.cpp index dcb783bb9d..02cd5957d3 100644 --- a/src/autotype/mac/AutoTypeMac.cpp +++ b/src/autotype/mac/AutoTypeMac.cpp @@ -232,6 +232,9 @@ AutoTypeAction::Result AutoTypeExecutorMac::execType(const AutoTypeKey* action) if (action->modifiers & Qt::AltModifier) { m_platform->sendKey(Qt::Key_Alt, true); } + if (action->modifiers & Qt::MetaModifier) { + m_platform->sendKey(Qt::Key_Meta, true); + } if (action->key != Qt::Key_unknown) { m_platform->sendKey(action->key, true); @@ -250,6 +253,9 @@ AutoTypeAction::Result AutoTypeExecutorMac::execType(const AutoTypeKey* action) if (action->modifiers & Qt::AltModifier) { m_platform->sendKey(Qt::Key_Alt, false); } + if (action->modifiers & Qt::MetaModifier) { + m_platform->sendKey(Qt::Key_Meta, false); + } Tools::sleep(execDelayMs); return AutoTypeAction::Result::Ok(); diff --git a/src/autotype/windows/AutoTypeWindows.cpp b/src/autotype/windows/AutoTypeWindows.cpp index 39e854bc3a..d7913ff05f 100644 --- a/src/autotype/windows/AutoTypeWindows.cpp +++ b/src/autotype/windows/AutoTypeWindows.cpp @@ -279,6 +279,9 @@ AutoTypeAction::Result AutoTypeExecutorWin::execType(const AutoTypeKey* action) if (action->modifiers & Qt::AltModifier) { m_platform->sendKey(Qt::Key_Alt, true); } + if (action->modifiers & Qt::MetaModifier) { + m_platform->sendKey(Qt::Key_Meta, true); + } if (action->key != Qt::Key_unknown) { m_platform->sendKey(action->key, true); @@ -297,6 +300,9 @@ AutoTypeAction::Result AutoTypeExecutorWin::execType(const AutoTypeKey* action) if (action->modifiers & Qt::AltModifier) { m_platform->sendKey(Qt::Key_Alt, false); } + if (action->modifiers & Qt::MetaModifier) { + m_platform->sendKey(Qt::Key_Meta, false); + } Tools::sleep(execDelayMs); return AutoTypeAction::Result::Ok(); diff --git a/src/gui/osutils/macutils/MacUtils.cpp b/src/gui/osutils/macutils/MacUtils.cpp index 5b47516034..c7d91950fd 100644 --- a/src/gui/osutils/macutils/MacUtils.cpp +++ b/src/gui/osutils/macutils/MacUtils.cpp @@ -366,6 +366,10 @@ uint16 MacUtils::qtToNativeKeyCode(Qt::Key key) case Qt::Key_Shift: return kVK_Shift; case Qt::Key_Control: + return kVK_Control; + case Qt::Key_Alt: + return kVK_Option; + case Qt::Key_Meta: return kVK_Command; case Qt::Key_Backspace: return kVK_Delete; diff --git a/src/gui/osutils/winutils/WinUtils.cpp b/src/gui/osutils/winutils/WinUtils.cpp index d9c1b69072..3aec7d5f7f 100644 --- a/src/gui/osutils/winutils/WinUtils.cpp +++ b/src/gui/osutils/winutils/WinUtils.cpp @@ -265,6 +265,8 @@ WORD WinUtils::qtToNativeKeyCode(Qt::Key key) return VK_DELETE; // 0x2E case Qt::Key_Help: return VK_HELP; // 0x2F + case Qt::Key_Meta: + return VK_LWIN; // 0x5B case Qt::Key_F1: return VK_F1; // 0x70