Using
SendKeys
for UI development is the sign of some abuse. As to the on-screen keyboard, it's simply useless, if you want to make your keyboard system-global. Many applications (notably, WPF) don't even windowed controls for input controls, they will ignore your emulated keyboard messages. The only valid way to use it would be via the P/Invoked Windows API
SendInput
:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[
^],
http://www.pinvoke.net/default.aspx/user32.sendinput[
^].
Then you truly emulate a keyboard, as this function is low-level, acts as if you generated real hardware events, it is also very reliable and easy to use.
There is one related problem: your keyboard may steal input focus from a focused control, so you would not be able to input events, unless you take special measures to overcome this problem. For
System.Windows.Forms
, I described my solution here:
Application focus getting and losing[
^].
See also my past answers in related topics:
How to fire a Key Press event of a Key on button click in WPF[
^],
Creating a Virtual Keyboard[
^],
Programming on BACKSPACE button[
^].
And this one is on WPF:
How to fire a Key Press event of a Key on button click in WPF[
^].
Good luck,
—SA