Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Codes depend on which event you're listening to, an easy way to find what you want is by using the <em>JavaScript</em> Event KeyCode Test Page <a href="http://www.asquare.net/javascript/tests/KeyCode.html"><strong>here</strong></a> with test input, e.g. for a full stop (the <code>.</code> left of right shift) you have</p> <pre><code> onKeyDown onKeyPress onKeyUp event.keyCode 190 46 190 event.charCode 0 46 0 event.which 190 46 190 </code></pre> <p>and for the <code>.</code> on the numeric pad it is</p> <pre><code> onKeyDown onKeyPress onKeyUp event.keyCode 110 46 110 event.charCode 0 46 0 event.which 110 46 110 </code></pre> <p>As you can see, it is most uniform to check with <em>onKeyPress</em> with <em>charCode</em> which is it's unicode number; <code>String.fromCharCode(46); // "."</code>.</p> <p>There is a <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Constants">full list on <strong>the MDN page</strong> for <em>KeyboardEvent</em></a> where it is also stated</p> <blockquote> <p><strong>Note</strong>: Web developers shouldn't use keycode attribute of printable keys in keydown and keyup event handlers. As described above, keycode is not usable for checking character which will be inputted especially when Shift key or AltGr key is pressed. When web developers implement shortcut key handler, keypress event is better event for that purpose on Gecko at least. See <a href="https://developer.mozilla.org/en-US/docs/Gecko_Keypress_Event">Gecko Keypress Event</a> for the detail.</p> </blockquote> <p>You can observe the strange effects of using <em>AltGr</em> or <em>Shift</em> on <em>keyCode</em> with the key of choice in the test page I linked to as well.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload