0

The program runs in the background, minimized to the tray. When you press the global hotkey, a function is called that should output selected text to the console (from any windows OS application).

I use QClipboard. I understand how to output to the console what is already in the buffer clipboard->text();, I understand how to write from my application to the clipboard clipboard->setText(); But I don't know how to write selected text from any windows OS application to the buffer Thanks

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
  • 2
    The clipboard belongs to the user, not your application. Use [UI Automation](https://learn.microsoft.com/en-us/windows/win32/winauto/entry-uiauto-win32) and you won't have to trash the user's clipboard. – IInspectable Feb 20 '23 at 15:44
  • You probably want to implement a [clipboard format listener or a clipboard viewer](https://learn.microsoft.com/en-us/windows/win32/dataxchg/using-the-clipboard#monitoring-clipboard-contents) – Igor Tandetnik Feb 20 '23 at 16:57
  • @IgorTandetnik, I can do this via `clipboard->setText(); clipboard->text();` , as I wrote earlier, but this is within my application. – Constantine Feb 20 '23 at 21:05
  • @IInspectable Thank you for your response. Maybe you are right and I need to use IUIAutomation. Could you show a small example of usage? I've tried it and I'm having errors. added `LIBS += -lUIAutomationCore` in *.pro, `#include #include #include QString GetSelectedText() { QString selectedText; IUIAutomation *automation = nullptr; ....... }` `Unknown type name 'IUIAutomation'` – Constantine Feb 20 '23 at 21:08
  • A clipboard format listener gets notified whenever clipboard changes. If someone selects text in any Windows application and presses Ctrl+C, that text is copied to clipboard, at which point your listener would be notified and could retrieve the text from clipboard. Is this not what you want? – Igor Tandetnik Feb 20 '23 at 22:50
  • You appear to want to fake a paste operation from a user? This is something that is very easy to abuse, so most OS's don't let just any application do it. Is there a underlying problem you are trying to solve and this is the solution for that underlying problem? – Yakk - Adam Nevraumont Feb 22 '23 at 14:22
  • @Yakk-AdamNevraumont I have an app. This application works in the tray. Let's say I found a word in the browser (in any Windows OS application) and I can highlight it. If a word is highlighted when pressing the ctrl+alt+O hotkey, my application launches a function that reads this highlighted word from another application and then outputs the meaning of this word as a pop-up window. – Constantine Feb 23 '23 at 10:48
  • @IgorTandetnik, Yes, as I said earlier, what you suggest I have already done via `clipboard->setText(); clipboard->text();` That is, now my application can output to me what is already in the buffer and after pressing ctrl+C it outputs what has changed. But I want to avoid pressing ctrl+C – Constantine Feb 23 '23 at 11:20
  • @Constantine I mean, any app that can do that can also read passwords someone highlights. That kind of "looking over the user's shoulder" as they use other applications is restricted in modern OS's. – Yakk - Adam Nevraumont Feb 23 '23 at 14:24
  • @Constantine I don't know? Could be OCR for all I know; maybe it is just doing screenshots. If you want to know what it does, there are applications that let you see what APIs a program uses, like "spy++", written by microsoft. – Yakk - Adam Nevraumont Feb 23 '23 at 18:42

0 Answers0