How can I detect numeric keypad Enter in Javascript

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


it is possible to detect the numpad Enter as seperate key nowadays. With the KeyboardEvent.location property. this way you can firstly check the keycode 13 and after if the key is on the numpad which devines the numpad enter.

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/location

example:

    window.onkeydown=function(ev)
    {
         var e= ev || window.event,
         key = e.keyCode
         if ((key===13) && (e.location===3)) {
            console.log("got ya");
            console.log(e.location);
         }
   }

Tags:

Javascript