Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect numeric keypad Enter in Javascript

Tags:

javascript

I'd like to have Javascript respond to a keypress or keydown event from only the numeric keypad Enter key, not the usual Enter key. They both seem to generate the same event data according to the demo in the jQuery keypress docs, so I'm not sure it's possible.

like image 413
jfklein Avatar asked May 23 '12 20:05

jfklein


People also ask

How do you check if the Enter key is pressed in JavaScript?

To check if an “enter” key is pressed inside a textbox, just bind the keypress() to the textbox. $('#textbox'). keypress(function(event){ var keycode = (event.

How do you detect enter press?

To check whether user pressed ENTER key on webpage or on any input element, you can bind keypress or keydown event to that element or document object itself. Then in bind() function check the keycode of pressed key whether it's value is 13 is not.

What is the keycode for enter?

Enter and Numpad Enter both give the same keycode, i.e. 13, because browsers do not differentiate between the two keys.


1 Answers

They do generate the same keystroke data, at the level of abstraction that JavaScript has access to. Remember, JavaScript lives in a sandbox (the browser) and has no direct access to the underlying hardware (there are plenty of platforms that don't have a numeric keypad at all, but do have a browser).

This cannot be done.

EDIT:

Support for this has been added for some browsers but does not seem to be universal (see the other answer).

like image 197
Eric J. Avatar answered Sep 28 '22 19:09

Eric J.