C++ Get string from Clipboard on Linux
Did you try to find not a code first but a program with an implementation ? I did it for you and found a lot of implementations which use direct X11 calls. I think the most valuable is this but also you may read this. Just find any program and look for the sources. Try to look on wikipedia what applications use x11 clipboard/selection system.
The following programs specifically operate on data transfer
mechanisms:
xcutsel
transfers data from selections to cut buffers or vice versa
xclipboard
,glipper
(Gnome),parcellite
(LXDE), andklipper
(KDE) are
clipboard managers, maybewmcliphist
as wellxcb
shows the content of
the cut buffers and allows the user to manipulate them xselection,
xclip
,xsel
andxcopy
are command line programs that copy data to or
from the X selection. xcopy has a verbosity option that helps debug X
selection issues. parcellite also has the ability to read from and
write to specific X selections from the command line.
synergy
is a cross platform tool that allows you to share a clipboard across
multiple computers running multiple operating systems
xfce4-clipman-plugin
is a "clipboard history plugin for the Xfce4
panel" and also a clipboard manager xtranslate looks up words in the
Xselection in a multi-lingual dictionary autocutsel syncs cut buffer
and selection buffer
Shortly, in theory, X11 has 2 "clipboards": actually a keyboard and for selections - the text you selected immediately can be pasted anywhere you want by pressing middle-mouse button while actual "keyboard" is made for main/default clipboard purposes as exchange by different kind of objects.
P.S. I'd not work with x11 anymore after my experience. Enjoy :)
linux clipboard read/write in C
Maybe you can look at xclip and see how they have done it.
It provides an interface to X
selections ("the clipboard") from the
command line. It can read data from
standard in or a file and place it in
an X selection for pasting into other
X applications. xclip can also print
an X selection to standard out, which
can then be redirected to a file or
another program.
How can I copy the output of a command directly into my clipboard?
One way of doing it follows:
Install
xclip
, such as:sudo apt-get install xclip
Pipe the output into
xclip
to be copied into the clipboard:cat file | xclip
Paste the text you just copied into a
X
application:xclip -o
To paste somewhere else other than an X
application, such as a text area of a web page in a browser window, use:
cat file | xclip -selection clipboard
Consider creating an alias:
alias "c=xclip"
alias "v=xclip -o"
To see how useful this is, imagine I want to open my current path in a new terminal window (there may be other ways of doing it like Ctrl+T on some systems, but this is just for illustration purposes):
Terminal 1:
pwd | c
Terminal 2:
cd `v`
Notice the ` `
around v
. This executes v
as a command first and then substitutes it in-place for cd
to use.
Only copy the content to the X
clipboard
cat file | xclip
How to get a string in a copy?
It depends on the operating system that you are trying to do this in. Linux and windows have slightly different ways of doing this.
I am assuming you are trying to write a program that will be able to move variable information to the clipboard to allow a user to paste it where they want.
Windows
Here is a link that has an example of a c++ program that uses the clipboard:
link
Linux
Linux is a little more complicated. It depends on the specific distro and what clipboard you want to move information to and from. There are a couple popular command line programs that could help you out.
XClip will copy and paste information to or from the command line, and you can use it with a pipe to do a lot of things.
Here is another question very similar to yours link
Related Topics
What Does the C++ New Operator Do Other Than Allocation and a Ctor Call
Factor a Large Number Efficiently with Gmp
How to Add Playable(Such as Wav,Wmv) Header with Pcm Data/Buffer in iOS
C++ Destruction of Temporary Object in an Expression
How to Construct or Return the Underlying Deque from a Stack
Why Doesn't the Program Crash When I Call a Member Function Through a Null Pointer in C++
How to Stop Windows from Blocking the Program During a Window Drag or Menu Button Being Held Down
Could Not Load Spatialite Extension in Qsqlite ( Qt 5.9)
How to Make Camera Follow a 3D Object in Opengl
Trouble with Template Parameters Used in MACros
Access Violation Writing Location 0Xcccccccc
Tcp Winsock: Accept Multiple Connections/Clients
Why Can't Operator () of Stateless Functor Be Static
How to Exit X11 Program Without Error
Setting Extra Bits in a Bool Makes It True and False at the Same Time