Guest User

quick and hacky Windows clipboard viewer with .NET

a guest
May 9th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. // C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe Program.cs /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\PresentationCore.dll"
  2. using System;
  3. using System.Windows;
  4.  
  5. namespace DumpClipboard
  6. {
  7.     class Program
  8.     {
  9.         [STAThread]
  10.         static void Main(string[] args)
  11.         {
  12.             // http://msdn.microsoft.com/en-us/library/system.windows.clipboard.aspx
  13.             IDataObject dataObject = Clipboard.GetDataObject();
  14.             foreach (var dataFormat in dataObject.GetFormats(autoConvert: true))
  15.             {
  16.                 Console.WriteLine("* Data format: {0}", dataFormat);
  17.             }
  18.  
  19.             Array textDataFormats = Enum.GetValues(typeof(TextDataFormat));
  20.             for (int i = 0; i < textDataFormats.Length; ++i)
  21.             {
  22.                 TextDataFormat textFormat = (TextDataFormat) textDataFormats.GetValue(i);
  23.  
  24.                 if (Clipboard.ContainsText(textFormat))
  25.                 {
  26.                     String data = Clipboard.GetText(textFormat);
  27.                     Console.WriteLine("* Clipboard data as {0}", textFormat);
  28.                     foreach (Char c in data.ToCharArray())
  29.                     {
  30.                         Console.Write("{0:X4} ", Convert.ToInt32(c));
  31.                     }
  32.                     Console.WriteLine();
  33.                 }
  34.                 else
  35.                 {
  36.                     Console.WriteLine("* Clipboard data is not {0}", textFormat);
  37.                 }
  38.             }
  39.         }
  40.     }
  41. }
Add Comment
Please, Sign In to add comment