Why do Enter and Space keys behave differently for buttons?

后端 未结 2 1675
情深已故
情深已故 2021-02-18 19:14

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

Pressing Enter instantly \'clicks\' the button, even if you keep it the key dow

2条回答
  •  [愿得一人]
    2021-02-18 20:00

    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 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 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.

    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.

提交回复
热议问题