Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do Enter and Space keys behave differently for buttons?

Tags:

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 down. (So the 'click' happens on KeyDown).

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!

like image 538
Felix Avatar asked Apr 18 '13 18:04

Felix


People also ask

What is difference between space and enter?

It works correctly if ENTER is pressed on the keyboard to separate each number during input whereas on using SPACE it doesn't stop the input process.

What does Enter and Space do?

Pressing Enter instantly 'clicks' the button, even if you keep it the key down. (So the 'click' happens on KeyDown). 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.)

Which key is used to space?

The space bar, spacebar, blank, or space key Space bar is a key on a typewriter or alphanumeric keyboard in the form of a horizontal bar in the lowermost row, significantly wider than all other keys. Its main purpose is to conveniently enter a space, e.g., between words during typing.


1 Answers

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.

like image 51
phadaphunk Avatar answered Oct 04 '22 21:10

phadaphunk