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

280
Vistas
JS keydown + keypress + preventDefault

What we have:

  1. keydown event + preventDefault prevents keypress event (proof: https://stackoverflow.com/a/57401334/9398364)
  2. stopPropagation doesn't help at all
  3. We can't simulate keypress with dispatchEvent because we don't know full list of unprintable event.key values (which we can't just throw as unicode value using event.key.codePointAt(0))

What we need:

  1. Disable default browser keys reaction (i.e. tab press in chrome) without huge switch expression

  2. Detect keydown events because we need shift, ctrl and other keys events (event.code matters)

  3. Detect keypress events because we need to input unicode characters (event.key matters) without input event and without checking if it is unprintable character (such as shift and ctrl)

How?

UPD: Seems like non-unicode event.key has >1 length (source: https://stackoverflow.com/a/70401792/9398364) Is there any proof?

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

0

Solved like this:

    window.addEventListener('keydown', function (event)
        {
            onKeyboard(event.code);
            if (event.key.length === 1 && !event.ctrlKey && !event.metaKey)
            {
                const utf16Code = event.key.codePointAt(0);
                onKeyboardInput(utf16Code);
            }
            event.preventDefault();
        }, false);
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