mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-02 17:44:46 -05:00
parent
dab7047113
commit
0f3a2531e7
@ -172,7 +172,7 @@ void AutoTypePlatformMac::sendChar(const QChar& ch, bool isKeyDown)
|
|||||||
// Send key code to active window
|
// Send key code to active window
|
||||||
// see: Quartz Event Services
|
// see: Quartz Event Services
|
||||||
//
|
//
|
||||||
void AutoTypePlatformMac::sendKey(Qt::Key key, bool isKeyDown, Qt::KeyboardModifiers modifiers = 0)
|
void AutoTypePlatformMac::sendKey(Qt::Key key, bool isKeyDown, Qt::KeyboardModifiers modifiers)
|
||||||
{
|
{
|
||||||
uint16 keyCode = macUtils()->qtToNativeKeyCode(key);
|
uint16 keyCode = macUtils()->qtToNativeKeyCode(key);
|
||||||
if (keyCode == INVALID_KEYCODE) {
|
if (keyCode == INVALID_KEYCODE) {
|
||||||
@ -238,38 +238,22 @@ AutoTypeAction::Result AutoTypeExecutorMac::execBegin(const AutoTypeBegin* actio
|
|||||||
|
|
||||||
AutoTypeAction::Result AutoTypeExecutorMac::execType(const AutoTypeKey* action)
|
AutoTypeAction::Result AutoTypeExecutorMac::execType(const AutoTypeKey* action)
|
||||||
{
|
{
|
||||||
if (action->modifiers & Qt::ShiftModifier) {
|
|
||||||
m_platform->sendKey(Qt::Key_Shift, true);
|
|
||||||
}
|
|
||||||
if (action->modifiers & Qt::ControlModifier) {
|
|
||||||
m_platform->sendKey(Qt::Key_Control, true);
|
|
||||||
}
|
|
||||||
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) {
|
if (action->key != Qt::Key_unknown) {
|
||||||
m_platform->sendKey(action->key, true);
|
m_platform->sendKey(action->key, true, action->modifiers);
|
||||||
m_platform->sendKey(action->key, false);
|
m_platform->sendKey(action->key, false, action->modifiers);
|
||||||
} else {
|
} else {
|
||||||
m_platform->sendChar(action->character, true);
|
if (action->modifiers != Qt::NoModifier) {
|
||||||
m_platform->sendChar(action->character, false);
|
// If we have modifiers set than we intend to send a key sequence
|
||||||
}
|
// convert to uppercase to align with Qt Key mappings
|
||||||
|
int ch = action->character.toUpper().toLatin1();
|
||||||
if (action->modifiers & Qt::ShiftModifier) {
|
m_platform->sendKey(static_cast<Qt::Key>(ch), true, action->modifiers);
|
||||||
m_platform->sendKey(Qt::Key_Shift, false);
|
m_platform->sendKey(static_cast<Qt::Key>(ch), false, action->modifiers);
|
||||||
}
|
} else {
|
||||||
if (action->modifiers & Qt::ControlModifier) {
|
m_platform->sendChar(action->character, true);
|
||||||
m_platform->sendKey(Qt::Key_Control, false);
|
m_platform->sendChar(action->character, false);
|
||||||
}
|
}
|
||||||
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);
|
Tools::sleep(execDelayMs);
|
||||||
|
@ -45,7 +45,7 @@ public:
|
|||||||
bool raiseOwnWindow() override;
|
bool raiseOwnWindow() override;
|
||||||
|
|
||||||
void sendChar(const QChar& ch, bool isKeyDown);
|
void sendChar(const QChar& ch, bool isKeyDown);
|
||||||
void sendKey(Qt::Key key, bool isKeyDown, Qt::KeyboardModifiers modifiers);
|
void sendKey(Qt::Key key, bool isKeyDown, Qt::KeyboardModifiers modifiers = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int windowLayer(CFDictionaryRef window);
|
static int windowLayer(CFDictionaryRef window);
|
||||||
|
@ -185,7 +185,6 @@ void MacUtils::registerNativeEventFilter()
|
|||||||
bool MacUtils::registerGlobalShortcut(const QString& name, Qt::Key key, Qt::KeyboardModifiers modifiers, QString* error)
|
bool MacUtils::registerGlobalShortcut(const QString& name, Qt::Key key, Qt::KeyboardModifiers modifiers, QString* error)
|
||||||
{
|
{
|
||||||
auto keycode = qtToNativeKeyCode(key);
|
auto keycode = qtToNativeKeyCode(key);
|
||||||
auto modifierscode = qtToNativeModifiers(modifiers, false);
|
|
||||||
if (keycode == INVALID_KEYCODE) {
|
if (keycode == INVALID_KEYCODE) {
|
||||||
if (error) {
|
if (error) {
|
||||||
*error = tr("Invalid key code");
|
*error = tr("Invalid key code");
|
||||||
@ -193,6 +192,16 @@ bool MacUtils::registerGlobalShortcut(const QString& name, Qt::Key key, Qt::Keyb
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Qt inverts CMD and CTRL on macOS under the hood, undo this
|
||||||
|
if (modifiers & Qt::MetaModifier && !(modifiers & Qt::ControlModifier)) {
|
||||||
|
modifiers &= ~Qt::MetaModifier;
|
||||||
|
modifiers |= Qt::ControlModifier;
|
||||||
|
} else if (modifiers & Qt::ControlModifier && !(modifiers & Qt::MetaModifier)) {
|
||||||
|
modifiers &= ~Qt::ControlModifier;
|
||||||
|
modifiers |= Qt::MetaModifier;
|
||||||
|
}
|
||||||
|
auto modifierscode = qtToNativeModifiers(modifiers, false);
|
||||||
|
|
||||||
// Check if this key combo is registered to another shortcut
|
// Check if this key combo is registered to another shortcut
|
||||||
QHashIterator<QString, QSharedPointer<globalShortcut>> i(m_globalShortcuts);
|
QHashIterator<QString, QSharedPointer<globalShortcut>> i(m_globalShortcuts);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
@ -440,7 +449,6 @@ uint16 MacUtils::qtToNativeKeyCode(Qt::Key key)
|
|||||||
return kVK_F16;
|
return kVK_F16;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Q_ASSERT(false);
|
|
||||||
return INVALID_KEYCODE;
|
return INVALID_KEYCODE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -469,13 +477,13 @@ CGEventFlags MacUtils::qtToNativeModifiers(Qt::KeyboardModifiers modifiers, bool
|
|||||||
nativeModifiers = CGEventFlags(nativeModifiers | shiftMod);
|
nativeModifiers = CGEventFlags(nativeModifiers | shiftMod);
|
||||||
}
|
}
|
||||||
if (modifiers & Qt::ControlModifier) {
|
if (modifiers & Qt::ControlModifier) {
|
||||||
nativeModifiers = CGEventFlags(nativeModifiers | cmdMod);
|
nativeModifiers = CGEventFlags(nativeModifiers | controlMod);
|
||||||
}
|
}
|
||||||
if (modifiers & Qt::AltModifier) {
|
if (modifiers & Qt::AltModifier) {
|
||||||
nativeModifiers = CGEventFlags(nativeModifiers | optionMod);
|
nativeModifiers = CGEventFlags(nativeModifiers | optionMod);
|
||||||
}
|
}
|
||||||
if (modifiers & Qt::MetaModifier) {
|
if (modifiers & Qt::MetaModifier) {
|
||||||
nativeModifiers = CGEventFlags(nativeModifiers | controlMod);
|
nativeModifiers = CGEventFlags(nativeModifiers | cmdMod);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nativeModifiers;
|
return nativeModifiers;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user