get data from text file and send to text field

I need to make something like copy and paste

Having file, get string from here, need to send (paste) it to the field where cursor now at.

Please advise
Last edited on
What field? What library/framework are you using with C++ for gui?
Im using Qt Editor, but I think it does not matter.

any field where you can print, I'm making AutoHotKey analog, when I press lets say ctrl + T, I want to send some text from file to field (webrowser text field, command line text field, or word document text field)
Im using Qt Editor, but I think it does not matter.

It does matter. If it's "your" application that you control, then you can simply do something like this, for example:

1
2
QTextEdit *myTextEdit = /* .. */
QString text = myTextEdit->textCursor().selectedText();

...assuming your are writing a Qt-based application with a QTextEdit widget:
https://doc.qt.io/qt-6/qtextedit.html#details

(There are similar ways with other widgets, such as a QLineEdit)


If you want to "exfiltrate" the text from a third-party application, things will be more difficult!

You can install a clipboard listener, so that your application will be informed, via WM_CLIPBOARDUPDATE, on every clipboard change:
https://learn.microsoft.com/de-de/windows/win32/api/winuser/nf-winuser-addclipboardformatlistener

You can then get the clipboard contents, after each change, via OpenClipboard() + GetClipboardData() + CloseClipboard().

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-openclipboard
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclipboarddata
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-closeclipboard

But there is no easy way to "force" a third-party application to copy the desired text to the clipboard... 🤔
Last edited on
Topic archived. No new replies allowed.