[UWP]如何检测按钮中的Enter键?

问题描述:

我注意到在UWP中当按钮处于焦点并且从键盘按下Enter键时,会触发Click事件。但是,当我按住回车键几秒钟时,会触发按键事件。如何让enter键调用另一个函数
键而不是Click事件?

I noticed that in UWP when a button is in focus and the Enter key is pressed from Keyboard, the Click Event is triggered. But, when I hold the enter key for some seconds, the key down event is triggered. How can I make the enter key to call another function of key down instead of Click Event?

嗨SubashAdhi,

Hi SubashAd

如您所知,当我们按Enter键一次时,Click事件将被触发。

As you know, when we press the Enter key once, the Click event will be fired.

如果您想按一下Enter键以触发KeyDown事件,您应该能够自定义Button控件。似乎Enter键将触发Click事件是设计的。

If you want to press the Enter once to fire the KeyDown event, you should able to custom a Button control. It seems the Enter key will fire the Click event is by design.

如果您想按住回车键几秒钟来触发KeyDown事件而不触发Click事件,应该能够使用Tap事件代替Click事件。

If you want to hold the enter key for some seconds to fire the KeyDown event and not fire the Click event, you should able to use Tap event to instead Click event.

最好的问候,

Jayden Gu

Jayden Gu