I'm building a customized virtual keyboard in C#.
The main point is sending a specific keypress to the window that currently has focus. But, normally, the key on the virtual keyboard will grab focus after it's pressed.
I'm assuming that some sort of Windows API should be used for this purpose. If so, which one, if not, what's the right way of doing it?
Best Answer
Here's a good resource on this topic: http://www.yortondotnet.com/2006/11/on-screen-keyboards.html
Basically, create a form and use labels for the keys instead of buttons. You will need to override CreateParams to set the correct style. You must also override WndProc and filter out the messages that normally send focus to your form. Then add click events to your labels and use
SendKeys.Send(keyPressed);
to send the actual keystroke to the window with focus.Here is the relevant code from the link: