As the topic, i know that is a way to get clipboard text but i wanna get the data from clipboard only when user click copy or trigger CTRL+C.
I found this X11 Wait for and Get Clipboard Text but isn't for windows.
I tried also that but the result doesn't satisfy me.
std::string GetClipboardText() {
// Try opening the clipboard
if (! OpenClipboard(nullptr))
... // error
// Get handle of clipboard object for ANSI text
HANDLE hData = GetClipboardData(CF_TEXT);
if (hData == nullptr)
... // error
// Lock the handle to get the actual text pointer
char * pszText = static_cast<char*>( GlobalLock(hData) );
if (pszText == nullptr)
... // error
// Save text in a string class instance
std::string text( pszText );
// Release the lock
GlobalUnlock( hData );
// Release the clipboard
CloseClipboard();
return text;
}