I am wonder if wxWidgets supports accessing/editing windows clipboard content, and if wxWidgets have 'global'(e.g:outside wxWidgets main window, in a browser or some other application) key pressed/released etc event detection capability.
I am planning writing an application using wxWidgets that reads stuff from a csv, whenever you press a key-combination, the application reads from csv certain field's contents, then copies it to the windows clipboard. It will a lot easier if wxWidgets supports such functions.
Thanks.
wxwidgets accessing windows clipboard and key/key-combo hook question
-
- Experienced Solver
- Posts: 81
- Joined: Wed Oct 19, 2016 1:41 pm
Re: wxwidgets accessing windows clipboard and key/key-combo hook question
See wxClipboard class and wxWindow::RegisterHotKey() function in the docs.
-
- Experienced Solver
- Posts: 81
- Joined: Wed Oct 19, 2016 1:41 pm
Re: wxwidgets accessing windows clipboard and key/key-combo hook question
Thanks for the tips, I will look at the docs a bit.catalin wrote:See wxClipboard class and wxWindow::RegisterHotKey() function in the docs.
Re: wxwidgets accessing windows clipboard and key/key-combo hook question
You could indeed use those two classes, I use them too and they're really helpful.
Register the hotkey and make sure to unregister them as well.
Use the wxEVT_HOTKEY event to handle the combinations.
I remember that I used MSW MOD_SHIFT instead of the wxWidgets variant for some reason, but I am not sure whether that was because they wouldn't work otherwise. Something to keep in mind if they don't work out of the box.
This is the code I use to fill the clipboard:
And I use this to read the clipboard:
Register the hotkey and make sure to unregister them as well.
Use the wxEVT_HOTKEY event to handle the combinations.
I remember that I used MSW MOD_SHIFT instead of the wxWidgets variant for some reason, but I am not sure whether that was because they wouldn't work otherwise. Something to keep in mind if they don't work out of the box.
This is the code I use to fill the clipboard:
Code: Select all
void INativeUser::insertTextToClipboard(const std::wstring& wsText) {
if (wxTheClipboard->Open())
{
wxTheClipboard->Clear();
wxTheClipboard->SetData(new wxTextDataObject(wsText));
wxTheClipboard->Flush();
wxTheClipboard->Close();
}
else {
//log error (L"Failed to insert text into clipboard (closed): '" + wsText + L"'.", Log::FAILURE);
}
}
Code: Select all
std::wstring INativeUser::getClipboardText() {
std::wstring ret;
if (wxTheClipboard->Open())
{
if (wxTheClipboard->IsSupported(wxDF_UNICODETEXT))
{
wxTextDataObject data;
wxTheClipboard->GetData(data);
ret = data.GetText().ToStdWstring();
}
wxTheClipboard->Close();
}
return ret;
}