Reputation: 33
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
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
Reputation: 9861
This gets asked every single day:
How to simulate key presses in C#
Keypress To Simulate A Button Click in C#
Upvotes: 6