mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-05 01:15:33 -05:00
Add command modifier support for AutoTypePlatformMac::sendKey
This commit is contained in:
parent
7620395f92
commit
268f09160d
@ -201,15 +201,25 @@ void AutoTypePlatformMac::sendChar(const QChar& ch, bool isKeyDown)
|
||||
// Send key code to active window
|
||||
// see: Quartz Event Services
|
||||
//
|
||||
void AutoTypePlatformMac::sendKey(Qt::Key key, bool isKeyDown)
|
||||
void AutoTypePlatformMac::sendKey(Qt::Key key, bool isKeyDown, bool isCommand = false)
|
||||
{
|
||||
uint16 keyCode = qtToNativeKeyCode(key);
|
||||
uint16 keyCode = 0;
|
||||
|
||||
if (isCommand && key == Qt::Key_Any) {
|
||||
keyCode = kVK_Command;
|
||||
} else {
|
||||
keyCode = qtToNativeKeyCode(key);
|
||||
}
|
||||
|
||||
if (keyCode == INVALID_KEYCODE) {
|
||||
return;
|
||||
}
|
||||
|
||||
CGEventRef keyEvent = ::CGEventCreateKeyboardEvent(nullptr, keyCode, isKeyDown);
|
||||
if (keyEvent != nullptr) {
|
||||
if (isCommand && isKeyDown) {
|
||||
::CGEventSetFlags(keyEvent, kCGEventFlagMaskCommand);
|
||||
}
|
||||
::CGEventPost(kCGSessionEventTap, keyEvent);
|
||||
::CFRelease(keyEvent);
|
||||
}
|
||||
@ -489,29 +499,13 @@ void AutoTypeExecutorMac::execKey(AutoTypeKey* action)
|
||||
usleep(25 * 1000);
|
||||
}
|
||||
|
||||
void execKeyPress(uint16 keyCode, bool isKeyDown, bool modifier = false)
|
||||
{
|
||||
CGEventRef keyEvent = ::CGEventCreateKeyboardEvent(nullptr, keyCode, isKeyDown);
|
||||
if (keyEvent != nullptr) {
|
||||
if (modifier) {
|
||||
::CGEventSetFlags(keyEvent, kCGEventFlagMaskCommand);
|
||||
}
|
||||
|
||||
::CGEventPost(kCGSessionEventTap, keyEvent);
|
||||
::CFRelease(keyEvent);
|
||||
}
|
||||
usleep(25 * 1000);
|
||||
}
|
||||
|
||||
void AutoTypeExecutorMac::execClearField(AutoTypeClearField* action = nullptr)
|
||||
{
|
||||
Q_UNUSED(action);
|
||||
|
||||
execKeyPress(kVK_ANSI_A, true, true);
|
||||
execKeyPress(kVK_ANSI_A, false);
|
||||
execKeyPress(kVK_Command, false);
|
||||
execKeyPress(kVK_Delete, true);
|
||||
execKeyPress(kVK_Delete, false);
|
||||
|
||||
m_platform->sendKey(Qt::Key_A, true, true);
|
||||
m_platform->sendKey(Qt::Key_A, false);
|
||||
m_platform->sendKey(Qt::Key_Any, false, true);
|
||||
m_platform->sendKey(Qt::Key_Backspace, true);
|
||||
m_platform->sendKey(Qt::Key_Backspace, false);
|
||||
usleep(25 * 1000);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
bool raiseOwnWindow() override;
|
||||
|
||||
void sendChar(const QChar& ch, bool isKeyDown);
|
||||
void sendKey(Qt::Key key, bool isKeyDown);
|
||||
void sendKey(Qt::Key key, bool isKeyDown, bool isCommand);
|
||||
|
||||
signals:
|
||||
void globalShortcutTriggered();
|
||||
|
Loading…
x
Reference in New Issue
Block a user