What you need is really the Windows Hook. The problem is, in this case, this is the global Windows Hook, and, according to Microsoft documentation, you cannot set up a global hook using just C# or .NET programming. The global hook requires that you install it in a separate native (unmanaged) DLL. If you do this, load this DLL in your .NET application and embed some kind of communication between the DLL and your .NET application in the DLL itself, because you can alway use a DLL method via P/Invoke.
Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632589%28v=vs.85%29.aspx[
^].
If you need to learn P/Invoke, start from here:
http://en.wikipedia.org/wiki/P/Invoke[
^],
http://msdn.microsoft.com/en-us/library/Aa712982[
^].
This CodeProject can also be useful:
Essential P/Invoke[
^].
One alternative to P/Invoke is to use C++/CLI mixed-mode (managed+unmanaged) project. This project could build a DLL required by the global hooks, but it can contain some managed wrapper CLI code, so, from the standpoint of your .NET application, you can use it as a regular .NET assembly, that is, reference it. Please see:
http://en.wikipedia.org/wiki/C%2B%2B/CLI[
^],
http://www.ecma-international.org/publications/standards/Ecma-372.htm[
^],
http://msdn.microsoft.com/en-us/library/xey702bw.aspx[
^],
http://msdn.microsoft.com/en-us/library/3bstk3k5[
^].
—SA