The hot key completely hides the message from other windows, as you said. What you need to do is to find the window with the focus and then read the text it has selected (and then possibly add it to the clipboard manually I guess?)
This snippet should find the focused window. It's in C++ but you can easily translate it to C#.
HWND GetGlobalFocus()
{
GUITHREADINGO info;
info.cbSize = sizeof(info);
if (!GetGUIThreadInfo(0, &info))
return NULL;
return info.hwndFocus;
}
Once you have that.. this is where it gets tricky. You could do a PostMessage(hWnd, WM_COPY, 0, 0);
but it won't work if the control doesn't support this (any syntax highlighted control is most likely non standard and as such might not reply to this).
You could manually send a WM_GETTEXT
message to get the text then manually add it to the clipboard, but again this will most likely fail it the control is heavily non-standard, not to mention that it won't preserve the applications possible multiple clipboard formats (think Word).
Another option is when you receive your hot key, disable your hook, send the key combination again with keybd_event
and then enable your hook again, and you'll have the data in your clipboard. This seems clunky but it could work depending if keybd_event
is blocking or not, I can't remember.
Hope this helps!