Search code examples
c#gtkclipboard

C# Mono Linux - Grab contents of global clipboard


I am trying to simply "grab" text from the clipboard and put into a variable. I'm having a lot of trouble doing this. I've tried to use

Gtk.Clipboard.Get(Gdk.Atom.Intern("PRIMARY", true))

The code that I have so far, just returns "Gtk.Clipboard" to TextBox entry1.

Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("PRIMARY", true));
string textClip = clipboard.ToString ();

entry1.Text = textClip;

So I am unable to do anything productive with this.


Solution

  • Try this piece of code to get text from system clipboard;

    Gtk.Clipboard clipboard = Gtk.Clipboard.Get(Gdk.Atom.Intern("CLIPBOARD", false));
    var text = clipboard.WaitForText();
    

    For more information mono documentation