send text to clipboard

Having some text that I want to send to clipboard, something like
string "random text", I want to call some function (C or 3rd party lib or can be Ubuntu tool)
so it would be possilbe to push Ctrl+V to paste random text

Thanks in Advance, I've googled and tried all possible options
Qt Clipboard lags, xdotool can do only paste.

There are might be X11 or libevdev, vendors I already use in my project, but I could not find relevant sample
I use https://linux.die.net/man/1/xsel for messing around with the clipboard from the command line.

Are you OK with trying out SDL?
SDL2 has these functions, and an SDL_Event structure if you want to catch a drag&drop event.

https://wiki.libsdl.org/SDL2/SDL_SetClipboardText
https://wiki.libsdl.org/SDL2/SDL_GetClipboardText
https://wiki.libsdl.org/SDL2/SDL_HasClipboardText

Drag&drop:
https://wiki.libsdl.org/SDL2/SDL_DropEvent
SFML also has clipboard support, something I didn't know.

https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Clipboard.php
It looks like the modern default Ubuntu does not come with a clipboard manager. That's partially the reason that clipboard data is deleted when a window is closed, X11 ties clipboard data to the window. While it's possible for a window to push the data to a new owner, I've never noticed any program that knows to do that.

You might want to try downloading a clipboard manager, the lack of one might be the reason that QT clipboard is having trouble. Looks like CopyQ is Qt based.


https://stackoverflow.com/questions/8755471/x11-wait-for-and-get-clipboard-text
Last edited on
Topic archived. No new replies allowed.