为什么 Enter 和 Space 键对于按钮的行为不同? [英] Why do Enter and Space keys behave differently for buttons?

查看:38
本文介绍了为什么 Enter 和 Space 键对于按钮的行为不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,当按钮获得焦点时,只有这些键会做出反应.

As far as I know, these are the only keys that react when a button has focus.

Enter 会立即点击"按钮,即使您一直按住按钮.(所以点击"发生在 KeyDown 上).

Pressing Enter instantly 'clicks' the button, even if you keep it the key down. (So the 'click' happens on KeyDown).

Space 更像是普通的鼠标点击;按住它不会激活 Click 事件,但是一旦你释放它就会激活.(因此点击"发生在 KeyUp 或 KeyPressed 上.)

Pressing Space acts more like a normal mouse click; holding it down doesn't activate the Click event, but it does once you release it. (So the 'click' happens on KeyUp or KeyPressed.)

为什么不同?我想要一篇关于这个主题的好文章,或者只是一个关于为什么这两个键具有不同行为的逻辑解释.肯定有解释!

Why the difference? I'd like a good article on the subject or simply a logical explanation as to why those two keys have different behavior. Surely there's an explanation out there!

推荐答案

我找不到任何解释这个问题的文章,这是一个非常好的问题.我个人认为这是出于功能目的

I can't find any articles explaining this and it's a really good question. I personally think that it's for functionality purposes

Enter Key 经典的 AcceptButton 就像一个 FullClick (Click/ClickReleased) 这就是为什么如果你按住它,你会有点击多次.

Enter Key the classic AcceptButton acts like a FullClick (Click/ClickReleased) that's why if you hold it you will have the effect of clicking multiple times.

Space 然而是一个 SingleClick(在你释放键之前没有点击释放)所以它可以完成只需要一个 Click 的任务没有 ClickRelease 和仅需要选择控件即可激活它的操作.像 CheckBoxRadioButtons 一样,它们不能用 Enter 激活,但可以用 Space 激活,比如如果你点击它.

Space however is a SingleClick (No click release until you release the key) so it can accomplish task where only a Click is required without a ClickRelease and actions where only the selection of a control is required to activate it. Like the CheckBox or RadioButtons which can't be activate with the Enter but can be activated with the Space like if you click on it.

总而言之,Space 将成为官方的 MouseClick,因为它在按下或释放时具有与 MouseClick 相同的效果.Enter 是一种一键全点击的快捷方式.当然,所有这些都是为了给键盘本身提供更多的可能性.

In conclusion, the Space would be the official MouseClick since it has the same effects of a MouseClick uppon pressing or releasing. Enter would be sort of a shortcut for a One click full click. All, of course, in the idea of giving more possibilities to the keyboard itself.

这篇关于为什么 Enter 和 Space 键对于按钮的行为不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆