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(); }).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() void StartCapturingClipboard()
{ {
std::thread([] std::thread([]
{ {
std::wstring last;
while (true) while (true)
{ {
Sleep(50); Sleep(50);
if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(NULL)) if (auto text = GetClipboardText())
{ if (last != text.value())
if (HANDLE clipboardHandle = GetClipboardData(CF_UNICODETEXT)) Host::GetThread(CLIPBOARD)->AddSentence(last = text.value());
{
if (wchar_t* clipboardData = (wchar_t*)GlobalLock(clipboardHandle))
{
static std::wstring last;
if (last != clipboardData) Host::GetThread(CLIPBOARD)->AddSentence(last = clipboardData);
GlobalUnlock(clipboardHandle);
} }
}
CloseClipboard();
}
}
}).detach(); }).detach();
} }
} }

View File

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