mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-03-01 10:51:20 -05:00
Change auto-type sequence on mac to support other keyboard layouts
This commit is contained in:
parent
a6e142dd02
commit
eefea5444e
@ -120,7 +120,7 @@ bool AutoTypePlatformMac::registerGlobalShortcut(Qt::Key key, Qt::KeyboardModifi
|
|||||||
qWarning("Invalid key code");
|
qWarning("Invalid key code");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint16 nativeModifiers = qtToNativeModifiers(modifiers);
|
CGEventFlags nativeModifiers = qtToNativeModifiers(modifiers, false);
|
||||||
if (::RegisterEventHotKey(nativeKeyCode, nativeModifiers, m_hotkeyId, GetApplicationEventTarget(), 0, &m_hotkeyRef) != noErr) {
|
if (::RegisterEventHotKey(nativeKeyCode, nativeModifiers, m_hotkeyId, GetApplicationEventTarget(), 0, &m_hotkeyRef) != noErr) {
|
||||||
qWarning("Register hotkey failed");
|
qWarning("Register hotkey failed");
|
||||||
return false;
|
return false;
|
||||||
@ -201,7 +201,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, bool isCommand = false)
|
void AutoTypePlatformMac::sendKey(Qt::Key key, bool isKeyDown, Qt::KeyboardModifiers modifiers = 0)
|
||||||
{
|
{
|
||||||
uint16 keyCode = qtToNativeKeyCode(key);
|
uint16 keyCode = qtToNativeKeyCode(key);
|
||||||
if (keyCode == INVALID_KEYCODE) {
|
if (keyCode == INVALID_KEYCODE) {
|
||||||
@ -209,10 +209,9 @@ void AutoTypePlatformMac::sendKey(Qt::Key key, bool isKeyDown, bool isCommand =
|
|||||||
}
|
}
|
||||||
|
|
||||||
CGEventRef keyEvent = ::CGEventCreateKeyboardEvent(nullptr, keyCode, isKeyDown);
|
CGEventRef keyEvent = ::CGEventCreateKeyboardEvent(nullptr, keyCode, isKeyDown);
|
||||||
|
CGEventFlags nativeModifiers = qtToNativeModifiers(modifiers, true);
|
||||||
if (keyEvent != nullptr) {
|
if (keyEvent != nullptr) {
|
||||||
if (isCommand && isKeyDown) {
|
::CGEventSetFlags(keyEvent, nativeModifiers);
|
||||||
::CGEventSetFlags(keyEvent, kCGEventFlagMaskCommand);
|
|
||||||
}
|
|
||||||
::CGEventPost(kCGSessionEventTap, keyEvent);
|
::CGEventPost(kCGSessionEventTap, keyEvent);
|
||||||
::CFRelease(keyEvent);
|
::CFRelease(keyEvent);
|
||||||
}
|
}
|
||||||
@ -320,6 +319,8 @@ uint16 AutoTypePlatformMac::qtToNativeKeyCode(Qt::Key key)
|
|||||||
case Qt::Key_Period:
|
case Qt::Key_Period:
|
||||||
return kVK_ANSI_Period;
|
return kVK_ANSI_Period;
|
||||||
|
|
||||||
|
case Qt::Key_Shift:
|
||||||
|
return kVK_Shift;
|
||||||
case Qt::Key_Control:
|
case Qt::Key_Control:
|
||||||
return kVK_Command;
|
return kVK_Command;
|
||||||
case Qt::Key_Backspace:
|
case Qt::Key_Backspace:
|
||||||
@ -400,21 +401,34 @@ uint16 AutoTypePlatformMac::qtToNativeKeyCode(Qt::Key key)
|
|||||||
// Translate qt key modifiers to mac os modifiers
|
// Translate qt key modifiers to mac os modifiers
|
||||||
// see: https://doc.qt.io/qt-5/osx-issues.html#special-keys
|
// see: https://doc.qt.io/qt-5/osx-issues.html#special-keys
|
||||||
//
|
//
|
||||||
uint16 AutoTypePlatformMac::qtToNativeModifiers(Qt::KeyboardModifiers modifiers)
|
CGEventFlags AutoTypePlatformMac::qtToNativeModifiers(Qt::KeyboardModifiers modifiers, bool native)
|
||||||
{
|
{
|
||||||
uint16 nativeModifiers = 0;
|
CGEventFlags nativeModifiers = 0;
|
||||||
|
|
||||||
|
CGEventFlags shiftMod = shiftKey;
|
||||||
|
CGEventFlags cmdMod = cmdKey;
|
||||||
|
CGEventFlags optionMod = optionKey;
|
||||||
|
CGEventFlags controlMod = controlKey;
|
||||||
|
|
||||||
|
if (native) {
|
||||||
|
shiftMod = kCGEventFlagMaskShift;
|
||||||
|
cmdMod = kCGEventFlagMaskCommand;
|
||||||
|
optionMod = kCGEventFlagMaskAlternate;
|
||||||
|
controlMod = kCGEventFlagMaskControl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (modifiers & Qt::ShiftModifier) {
|
if (modifiers & Qt::ShiftModifier) {
|
||||||
nativeModifiers |= shiftKey;
|
nativeModifiers |= shiftMod;
|
||||||
}
|
}
|
||||||
if (modifiers & Qt::ControlModifier) {
|
if (modifiers & Qt::ControlModifier) {
|
||||||
nativeModifiers |= cmdKey;
|
nativeModifiers |= cmdMod;
|
||||||
}
|
}
|
||||||
if (modifiers & Qt::AltModifier) {
|
if (modifiers & Qt::AltModifier) {
|
||||||
nativeModifiers |= optionKey;
|
nativeModifiers |= optionMod;
|
||||||
}
|
}
|
||||||
if (modifiers & Qt::MetaModifier) {
|
if (modifiers & Qt::MetaModifier) {
|
||||||
nativeModifiers |= controlKey;
|
nativeModifiers |= controlMod;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nativeModifiers;
|
return nativeModifiers;
|
||||||
@ -498,10 +512,18 @@ void AutoTypeExecutorMac::execClearField(AutoTypeClearField* action = nullptr)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(action);
|
Q_UNUSED(action);
|
||||||
|
|
||||||
m_platform->sendKey(Qt::Key_Control, true, true);
|
m_platform->sendKey(Qt::Key_Control, true, Qt::ControlModifier);
|
||||||
m_platform->sendKey(Qt::Key_A, true, true);
|
m_platform->sendKey(Qt::Key_Up, true, Qt::ControlModifier);
|
||||||
m_platform->sendKey(Qt::Key_Control, false, true);
|
m_platform->sendKey(Qt::Key_Up, false, Qt::ControlModifier);
|
||||||
m_platform->sendKey(Qt::Key_A, false);
|
m_platform->sendKey(Qt::Key_Control, false);
|
||||||
|
usleep(25 * 1000);
|
||||||
|
m_platform->sendKey(Qt::Key_Shift, true, Qt::ShiftModifier);
|
||||||
|
m_platform->sendKey(Qt::Key_Control, true, Qt::ShiftModifier | Qt::ControlModifier);
|
||||||
|
m_platform->sendKey(Qt::Key_Down, true, Qt::ShiftModifier | Qt::ControlModifier);
|
||||||
|
m_platform->sendKey(Qt::Key_Down, false, Qt::ShiftModifier | Qt::ControlModifier);
|
||||||
|
m_platform->sendKey(Qt::Key_Control, false, Qt::ShiftModifier);
|
||||||
|
m_platform->sendKey(Qt::Key_Shift, false);
|
||||||
|
usleep(25 * 1000);
|
||||||
m_platform->sendKey(Qt::Key_Backspace, true);
|
m_platform->sendKey(Qt::Key_Backspace, true);
|
||||||
m_platform->sendKey(Qt::Key_Backspace, false);
|
m_platform->sendKey(Qt::Key_Backspace, false);
|
||||||
|
|
||||||
|
@ -49,7 +49,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, bool isCommand);
|
void sendKey(Qt::Key key, bool isKeyDown, Qt::KeyboardModifiers modifiers);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void globalShortcutTriggered();
|
void globalShortcutTriggered();
|
||||||
@ -60,7 +60,7 @@ private:
|
|||||||
EventHotKeyID m_hotkeyId;
|
EventHotKeyID m_hotkeyId;
|
||||||
|
|
||||||
static uint16 qtToNativeKeyCode(Qt::Key key);
|
static uint16 qtToNativeKeyCode(Qt::Key key);
|
||||||
static uint16 qtToNativeModifiers(Qt::KeyboardModifiers modifiers);
|
static CGEventFlags qtToNativeModifiers(Qt::KeyboardModifiers modifiers, bool native);
|
||||||
static int windowLayer(CFDictionaryRef window);
|
static int windowLayer(CFDictionaryRef window);
|
||||||
static QString windowTitle(CFDictionaryRef window);
|
static QString windowTitle(CFDictionaryRef window);
|
||||||
static OSStatus hotkeyHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData);
|
static OSStatus hotkeyHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user