From 36250f518075d1b348eb4b63193590be5f0c608a Mon Sep 17 00:00:00 2001 From: Weslly Date: Sat, 25 Mar 2017 19:03:17 -0300 Subject: [PATCH] Use AutoTypePlatformWin::sendKey instead of creating a new function --- src/autotype/AutoTypeAction.cpp | 2 -- src/autotype/mac/AutoTypeMac.cpp | 2 ++ src/autotype/windows/AutoTypeWindows.cpp | 35 ++++++------------------ 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/autotype/AutoTypeAction.cpp b/src/autotype/AutoTypeAction.cpp index 090ca823..64dae796 100644 --- a/src/autotype/AutoTypeAction.cpp +++ b/src/autotype/AutoTypeAction.cpp @@ -90,6 +90,4 @@ void AutoTypeExecutor::execDelay(AutoTypeDelay* action) void AutoTypeExecutor::execClearField(AutoTypeClearField* action) { Q_UNUSED(action); - - // TODO: implement } diff --git a/src/autotype/mac/AutoTypeMac.cpp b/src/autotype/mac/AutoTypeMac.cpp index 122bffea..2806a448 100644 --- a/src/autotype/mac/AutoTypeMac.cpp +++ b/src/autotype/mac/AutoTypeMac.cpp @@ -502,10 +502,12 @@ void AutoTypeExecutorMac::execKey(AutoTypeKey* action) void AutoTypeExecutorMac::execClearField(AutoTypeClearField* action = nullptr) { Q_UNUSED(action); + 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); } diff --git a/src/autotype/windows/AutoTypeWindows.cpp b/src/autotype/windows/AutoTypeWindows.cpp index 3c8d896e..0b147441 100644 --- a/src/autotype/windows/AutoTypeWindows.cpp +++ b/src/autotype/windows/AutoTypeWindows.cpp @@ -189,6 +189,8 @@ DWORD AutoTypePlatformWin::qtToNativeKeyCode(Qt::Key key) case Qt::Key_Enter: case Qt::Key_Return: return VK_RETURN; // 0x0D + case Qt::Key_Control: + return VK_CONTROL; // 0x11 case Qt::Key_Pause: return VK_PAUSE; // 0x13 case Qt::Key_CapsLock: @@ -527,37 +529,16 @@ void AutoTypeExecutorWin::execKey(AutoTypeKey* action) ::Sleep(25); } -void execKeyPress(const DWORD keyCode, bool isKeyDown) -{ - DWORD nativeFlags = 0; - - if (!isKeyDown) { - nativeFlags |= KEYEVENTF_KEYUP; - } - - INPUT in; - in.type = INPUT_KEYBOARD; - in.ki.wVk = LOWORD(keyCode); - in.ki.wScan = LOWORD(::MapVirtualKeyW(keyCode, MAPVK_VK_TO_VSC)); - in.ki.dwFlags = nativeFlags; - in.ki.time = 0; - in.ki.dwExtraInfo = ::GetMessageExtraInfo(); - - ::SendInput(1, &in, sizeof(INPUT)); - - ::Sleep(25); -} - void AutoTypeExecutorWin::execClearField(AutoTypeClearField* action = nullptr) { Q_UNUSED(action); - execKeyPress(VK_CONTROL, true); - execKeyPress(0x41, true); - execKeyPress(0x41, false); - execKeyPress(VK_CONTROL, false); - execKeyPress(VK_BACK, true); - execKeyPress(VK_BACK, false); + m_platform->sendKey(Qt::Key_Control, true); + m_platform->sendKey(Qt::Key_A, true); + m_platform->sendKey(Qt::Key_A, false); + m_platform->sendKey(Qt::Key_Control, false); + m_platform->sendKey(Qt::Key_Backspace, true); + m_platform->sendKey(Qt::Key_Backspace, false); ::Sleep(25); }