A. Jefferson
A. Jefferson

Reputation: 33

Virtual keyboard in C#

I want to write an application that send various keycodes depending on which button the user clicked. How would I send the keycodes? For example, how to emulate the 'a' press? How about modifier keys?

Upvotes: 3

Views: 18357

Answers (2)

Chris Taylor
Chris Taylor

Reputation: 53699

Once you have got the sending of key presses to another window sorted out, you are going to face another problem. That is when the user clicks the button on your virtual keyboard the target window, the one you want to have receive the key press, will loose focus and the SendKeys will not seem to work.

There many solutions to this problem, but the quick and dirty solution that requires minimal effort is to change the style of your virtual keyboard window to include WS_EX_NOACTIVATE

See the answer I provided to the following question HERE for Windows Forms and if you want to do this using WPF I have a similar answer HERE

Upvotes: 1

Related Questions