This commit is contained in:
Akash Mozumdar 2018-11-15 00:16:12 -05:00
parent d9a3d5cefd
commit 0492cb9549
2 changed files with 21 additions and 15 deletions

View File

@ -143,28 +143,34 @@ namespace
}).detach();
}
std::optional<std::wstring> GetClipboardText()
{
if (!IsClipboardFormatAvailable(CF_UNICODETEXT)) return {};
if (!OpenClipboard(NULL)) return {};
if (HANDLE clipboardHandle = GetClipboardData(CF_UNICODETEXT))
{
std::wstring ret = (wchar_t*)GlobalLock(clipboardHandle);
GlobalUnlock(clipboardHandle);
CloseClipboard();
return ret;
}
CloseClipboard();
return {};
}
void StartCapturingClipboard()
{
std::thread([]
{
std::wstring last;
while (true)
{
Sleep(50);
if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL))
{
if (HANDLE clipboardHandle = GetClipboardData(CF_UNICODETEXT))
{
if (wchar_t* clipboardData = (wchar_t*)GlobalLock(clipboardHandle))
{
static std::wstring last;
if (last != clipboardData) Host::GetThread(CLIPBOARD)->AddSentence(last = clipboardData);
GlobalUnlock(clipboardHandle);
if (auto text = GetClipboardText())
if (last != text.value())
Host::GetThread(CLIPBOARD)->AddSentence(last = text.value());
}
}
CloseClipboard();
}
}
}).detach();
}
}

View File

@ -291,7 +291,7 @@ bool TextHook::InsertReadCode()
void TextHook::InitHook(HookParam h, LPCSTR name, DWORD set_flag)
{
LOCK(*sectionMutex);
this->hp = h;
hp = h;
hp.insertion_address = hp.address;
hp.type |= set_flag;
strcpy_s<HOOK_NAME_SIZE>(hookName, name);