How do I get the selected text from the focused window using native Win32 API?

Viewed 12900

My app. will be running on the system try monitoring for a hotkey; when the user selects some text in any window and presses a hotkey, how do I obtain the selected text, when I get the WM_HOTKEY message?

To capture the text on to the clipboard, I tried sending Ctrl + C using keybd_event() and SendInput() to the active window (GetActiveWindow()) and forground window (GetForegroundWindow()); tried combinations amongst these; all in vain. Can I get the selected text of the focused window in Windows with plain Win32 system APIs?

3 Answers

Try adding a Sleep() after each SendInput(). Some apps just aren't that fast in catching keyboard input.

Try SendMessage(WM_COPY, etc. ).

Related