Skip to content Skip to sidebar Skip to footer

Ctrl Keycode (17) Not Working In Javascript?

I have the following code which adds an eventListener to a HTML textarea. It's supposed to console log the keycode which was pressed, and, if the keyCode is == to 17 (CTRL), consol

Solution 1:

For some reason, special keys do not work with the keypress event, but they do with the keydown event.

Solution 2:

Try this instead: (e.which == 17)

Solution 3:

Check for e.ctrlKey.

See the MDN documentation at https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/ctrlKey

If you want an easy way to manage keypress you could use a dedicated library like https://dmauro.github.io/Keypress/

Post a Comment for "Ctrl Keycode (17) Not Working In Javascript?"