Aug 29, 2023 at 2:52pm UTC
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 Aug 30, 2023 at 5:00am UTC
Aug 29, 2023 at 3:41pm UTC
What field? What library/framework are you using with C++ for gui?
Aug 29, 2023 at 4:55pm UTC
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)
Aug 29, 2023 at 6:15pm UTC
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 Aug 29, 2023 at 6:27pm UTC