mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-10 11:48:30 -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
|
// Send key code to active window
|
||||||
// see: Quartz Event Services
|
// 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) {
|
if (keyCode == INVALID_KEYCODE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGEventRef keyEvent = ::CGEventCreateKeyboardEvent(nullptr, keyCode, isKeyDown);
|
CGEventRef keyEvent = ::CGEventCreateKeyboardEvent(nullptr, keyCode, isKeyDown);
|
||||||
if (keyEvent != nullptr) {
|
if (keyEvent != nullptr) {
|
||||||
|
if (isCommand && isKeyDown) {
|
||||||
|
::CGEventSetFlags(keyEvent, kCGEventFlagMaskCommand);
|
||||||
|
}
|
||||||
::CGEventPost(kCGSessionEventTap, keyEvent);
|
::CGEventPost(kCGSessionEventTap, keyEvent);
|
||||||
::CFRelease(keyEvent);
|
::CFRelease(keyEvent);
|
||||||
}
|
}
|
||||||
@ -489,29 +499,13 @@ void AutoTypeExecutorMac::execKey(AutoTypeKey* action)
|
|||||||
usleep(25 * 1000);
|
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)
|
void AutoTypeExecutorMac::execClearField(AutoTypeClearField* action = nullptr)
|
||||||
{
|
{
|
||||||
Q_UNUSED(action);
|
Q_UNUSED(action);
|
||||||
|
m_platform->sendKey(Qt::Key_A, true, true);
|
||||||
execKeyPress(kVK_ANSI_A, true, true);
|
m_platform->sendKey(Qt::Key_A, false);
|
||||||
execKeyPress(kVK_ANSI_A, false);
|
m_platform->sendKey(Qt::Key_Any, false, true);
|
||||||
execKeyPress(kVK_Command, false);
|
m_platform->sendKey(Qt::Key_Backspace, true);
|
||||||
execKeyPress(kVK_Delete, true);
|
m_platform->sendKey(Qt::Key_Backspace, false);
|
||||||
execKeyPress(kVK_Delete, false);
|
|
||||||
|
|
||||||
usleep(25 * 1000);
|
usleep(25 * 1000);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
void sendKey(Qt::Key key, bool isKeyDown, bool isCommand);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void globalShortcutTriggered();
|
void globalShortcutTriggered();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user