With jQuery, how do WE find out which key was pressed when WE bind to the keypress event?
Solution 1:
Actually this is better:
Solution 2:
Try this
Solution 3:
If we are using jQuery UWE we have translations for common key codes. In ui/ui/ui.core.js :
There's also some translations in tests/simulate/jquery.simulate.js but WE could not find any in the core JS library. Mind you, WE merely grep'ed the sources. Maybe there is some other way to get rid of these magic numbers.
We can also make use of String.charCodeAt and .fromCharCode:
Solution 4:
... this example prevents form submission (regularly the basic intention when capturing keystroke #13):