tags:

views:

1941

answers:

4

How can I send keyboard input messages to either the currently selected window or the previously selected window?

I have a program which I use to type some characters which are not present on my keyboard and I would like it if I could just send the input directly rather than me having to copy and paste all the time.

EDIT:

The application of this is typing the German Umlauts. I'm an American and I work in Germany. I'm working on an American keyboard and from time to time I have to type in the umlauts / the euro symbol / the sharp S. Currently I have a simple WinForms application with a textfield and some buttons with the extra characters on it. I type into the textfield and I can press the buttons to append text to the textfield. I then copy the text and paste it where ever. What would be nice though if I could just just hit one of the buttons and it would send the text where ever I'm typing / was typing. The current program works fairly well but I could make it better.

+5  A: 

SendKeys.Send will help you with that.

David Vidmar
+2  A: 

Look at System.Windows.Forms.SendKeys.Send( string ). This allows key presses to be sent to the currently active application.

Update: just found this on MSDN forums: MSDN Forum

ng5000
+1  A: 

If it's not present on your keyboard, you might simply add a button and send the code key of this character to the reference object you want to append this character. Give us an example of what you want, we might be able to show you some code.

Short example of code:

myField.Text += "®"; //This is a char that I do not have on my keyboard
Daok
A: 

And can you help me with sending MediaNextTrack keyboard input? I try it with SendKeys but it don't work...