If you need to send raw keyboard input, you need to do it before it was interpreted as character. That is, the only thing you can use is the Windows API function
SendInput
:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[
^].
With .NET, you can use it through P/Invoke, as this work is already done for you:
http://www.pinvoke.net/default.aspx/user32.sendinput[
^].
You should remember that using P/Invoke, at least for this API, is platform-specific, so by using it you will totally kill platform compatibility of your code. For example, under Mono, you can execute your BCL-based code, and also Forms applications (and a lot more) on Linux, Mac OS X and other platforms
without recompilation, but using this Windows-specific API will break such compatibility.
Besides, I just want to warn you: using such things for "regular" UI development and is not really required, and would be a big abuse. This functionality is used for some special effects; one such problem is playing keyboard (and mouse) macros.
—SA