3

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?

A. Jefferson
  • 33
  • 1
  • 1
  • 3

2 Answers2

6

This gets asked every single day:

How to simulate key presses in C#

Simulating Key Press c#

Keypress To Simulate A Button Click in C#

How to simulate keypress

Community
  • 1
  • 1
satnhak
  • 9,407
  • 5
  • 63
  • 81
  • I asked this on SO some time ago, and got even answer about how to simulate key release : http://stackoverflow.com/questions/172353/how-to-push-a-key-and-release-it-using-c – Larry Apr 23 '11 at 12:02
0

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

Community
  • 1
  • 1
Chris Taylor
  • 52,623
  • 10
  • 78
  • 89