Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

269
Vistas
keyDown doesn't produce the same keys and codes across browsers, what are some solutions to this issue?

Objective: Listen for key press events to catch printable characters.

Problem: keyPress, the perfect solution for this issue, is deprecated and not recommended anymore, and the alternative keyDown doesn't produce the same key and code values as keyPress for printable characters, and it's also inconsistent with it self across browsers.

Reproduce: If you wish to attempt reproducing the issue, use this website different browsers and compare your results

Example: when pressing ; on keyboard:

  1. Chrome ❌
Event key code which charCode
keyDown . 190 0 0
keyPress ; 59 59 59
keyUp . 190 0 0
  1. Firefox ✅
Event key code which charCode
keyDown ; 59 59 59
keyPress ; 59 59 59
keyUp ; 59 59 59

Current Solution: I'm using keyDown and allowing only key values that match a RegEx to be processed.

Note: I'm using a keyboard with 2 languages, but I don't think this is should interfere with anything, since keyPress works fine.

Question: How can I get keyDown to produce same correct keyCode values that keyPress produces across browsers? Or should I just use keyPress dispite it being not recommended anymore.

EDIT: You may want to check out 3.3. Key Code Values of this clever and well detailed article about this problem to better understand this issue

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

See MDN:

KeyboardEvent.keyCode

Deprecated: This feature is no longer recommended.

and

You should avoid using this if possible; it's been deprecated for some time. Instead, you should use KeyboardEvent.code,

const kbd = document.querySelector('kbd');
document.querySelector('input').addEventListener('keydown', e => {
  kbd.innerText = e.code;
});
<input>
<kbd></kbd>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda