Sending a key on window changed event
I have a Window state changed event in WPF. I want to send an ESCAPE key wh开发者_开发问答en the event fires.
Can any1 help me out how to do that?
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
精彩评论