tags:

views:

13

answers:

1

I have a Window state changed event in WPF. I want to send an ESCAPE key when the event fires.

Can any1 help me out how to do that?

+1  A: 

I would suggest you throw other events than to simulate keyboard events.

If you really really wish to send a Key event, take a look at the KeyEventArgs:

RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, Key.Escape));

The first argument says its your keyboard, and the second argument says it will be send to your ActiveSource, which hopefully will be your WPF window ;)

You can raise the event from the code behind of any WPF control

However it's much better just to introduce a custom event, and call the methods which you expect to happen than to send an escape event key.

Hope this helps

Arcturus