Writing a clipboard viewer in C#

mozart picture mozart · Aug 6, 2009 · Viewed 7.4k times · Source

I want to write program to learn vocabulary. Simply each time, when I copy a word to clipboard, It will save them to text file.

so, there are requirements, I think that is:

  1. My program run in background like keylogger?
  2. Detect even and save words to text file everytime I copy a word to clipboard.?

all done by C#. so, plz give me some advice! thank you very much!

Answer

sylvanaar picture sylvanaar · Aug 6, 2009

There's an example in the .NET SDK called ClipboardSpy.

Here's an example even:

static void Main(string[] args)
{
    while (true)
    {
        if (Clipboard.ContainsText())
        {
            string s = Clipboard.GetText();

            Console.WriteLine(s);

            Clipboard.Clear();
        }
    }
}