I want to create an application on Windows that can automatically add selected text in current active window of other application to the clipboard, so I can paste the selected text to my favorite editor without an explicit copy or cut is made first. Any tips on how to get started ?
Asked
Active
Viewed 653 times
1
-
1Use a timer to send `WM_PASTE` to the focus window every 50th of a second. (only joking) – Jonathan Potter Nov 06 '15 at 03:40
-
1Or use X11 instead when this feature was enabled by default for _everything_. On a more serious note, maybe create a listener for mouse-up events in the active window that will grab that text specific to your toolkit, then do something like this: http://stackoverflow.com/a/4203897/2904896 – metatoaster Nov 06 '15 at 03:52
-
@metatoaster the active window maybe a PDF reader, I found it is hard to create a listener for mouse-up events in this case . – iMath Nov 06 '15 at 04:47
-
It doesn't matter what the active window is if you have [global hook](http://stackoverflow.com/a/10818037/2904896). – metatoaster Nov 06 '15 at 05:01
-
1Qt doesn't use native Windows controls (for better or worse). You cannot use the window manager's facilities for this, with the exception, maybe, to send a `WM_COPY` message. You'll have to look into [UI Automation](https://msdn.microsoft.com/en-us/library/windows/desktop/ee684009.aspx) or [WinEvents](https://msdn.microsoft.com/en-us/library/windows/desktop/dd373889.aspx), if the application(s) implement those. The latter has an [EVENT_OBJECT_SELECTION](https://msdn.microsoft.com/en-us/library/windows/desktop/dd318066.aspx#EVENT_OBJECT_NAMECHANGE) event, that may be what you're looking for. – IInspectable Nov 06 '15 at 10:35
-
@NicolasHolthaus: `QClipboard` wraps the trivial implementation to access the clipboard. This doesn't help much. Simulating keyboard input to trigger a copy is not clever. It is the wrong solution, too, if anything. What about controls, that don't listen to keyboard messages, and respond to `WM_COPY` messages only? Plus, you are completely ignoring the difficult part: Monitoring selection changes. – IInspectable Nov 06 '15 at 13:53
-
1[auto copy mouse selection with drag king](http://www.techinfoweb.com/auto-copy-mouse-selection-with-drag-king/). – ekhumoro Nov 06 '15 at 17:16