Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1.  
  2. using System.Threading.Tasks;
  3.  
  4. namespace NiHaoRS
  5. {
  6.    
  7.    
  8.     public class LinuxClipboard
  9.         : GenericClipboard
  10.  
  11.     {
  12.  
  13.         public LinuxClipboard()
  14.         { }
  15.        
  16.        
  17.         public static async Task TestClipboard()
  18.         {
  19.             GenericClipboard lc = new LinuxClipboard();
  20.             await lc.SetClipboardContentsAsync("Hello KLIPPY");
  21.             string cc = await lc.GetClipboardContentAsync();
  22.             System.Console.WriteLine(cc);
  23.         } // End Sub TestClipboard
  24.        
  25.        
  26.         public override async Task SetClipboardContentsAsync(string text)
  27.         {
  28.             Tmds.DBus.ObjectPath objectPath = new Tmds.DBus.ObjectPath("/klipper");
  29.             string service = "org.kde.klipper";
  30.  
  31.             using (Tmds.DBus.Connection connection = new Tmds.DBus.Connection(Tmds.DBus.Address.Session))
  32.             {
  33.                 await connection.ConnectAsync();
  34.  
  35.                 Klipper.DBus.IKlipper klipper = connection.CreateProxy<Klipper.DBus.IKlipper>(service, objectPath);
  36.                 await klipper.setClipboardContentsAsync(text);
  37.             } // End using connection
  38.  
  39.         } // End Task SetClipboardContentsAsync
  40.        
  41.        
  42.         public override async Task<string> GetClipboardContentAsync()
  43.         {
  44.             string clipboardContents = null;
  45.  
  46.             Tmds.DBus.ObjectPath objectPath = new Tmds.DBus.ObjectPath("/klipper");
  47.             string service = "org.kde.klipper";
  48.  
  49.             using (Tmds.DBus.Connection connection = new Tmds.DBus.Connection(Tmds.DBus.Address.Session))
  50.             {
  51.                 await connection.ConnectAsync();
  52.  
  53.                 Klipper.DBus.IKlipper klipper = connection.CreateProxy<Klipper.DBus.IKlipper>(service, objectPath);
  54.  
  55.                 clipboardContents = await klipper.getClipboardContentsAsync();
  56.             } // End Using connection
  57.  
  58.             return clipboardContents;
  59.         } // End Task GetClipboardContentsAsync
  60.        
  61.        
  62.     } // End Class LinuxClipBoardAPI
  63.    
  64.    
  65. } // End Namespace NiHaoRS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement