From 28678f4e06cb1f466a6ed4c3081bc9ad95fcabbc Mon Sep 17 00:00:00 2001 From: Weslly Date: Fri, 24 Mar 2017 10:15:31 -0300 Subject: [PATCH] Add auto-type {CLEARFIELD} on Windows --- src/autotype/windows/AutoTypeWindows.cpp | 34 ++++++++++++++++++++++++ src/autotype/windows/AutoTypeWindows.h | 1 + 2 files changed, 35 insertions(+) diff --git a/src/autotype/windows/AutoTypeWindows.cpp b/src/autotype/windows/AutoTypeWindows.cpp index 0818a37bc..3c8d896ed 100644 --- a/src/autotype/windows/AutoTypeWindows.cpp +++ b/src/autotype/windows/AutoTypeWindows.cpp @@ -527,3 +527,37 @@ 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); + + ::Sleep(25); +} diff --git a/src/autotype/windows/AutoTypeWindows.h b/src/autotype/windows/AutoTypeWindows.h index f8b213cb0..6ffae4d1e 100644 --- a/src/autotype/windows/AutoTypeWindows.h +++ b/src/autotype/windows/AutoTypeWindows.h @@ -64,6 +64,7 @@ public: void execChar(AutoTypeChar* action) override; void execKey(AutoTypeKey* action) override; + void execClearField(AutoTypeClearField* action) override; private: AutoTypePlatformWin* const m_platform;