开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜