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

263
Vistas
How to detect if the event that is generated belongs to Keyboard, Pointer or Form Event?

I have developing an application that records the events and replays them. For that I need to identify what kind of event is being generated because mouse, keyboard and form events behave differently from each other.

Right now i am trying to use: e instanceof KeyboardEvent but this doesn't seems to be working. What is the better way of identifying to which event family it belongs to?

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

0

A basic example for a mouse and keyboard event. You just have to add an eventListener to your desired dom element. And then you have to check if the triggered event e is an instance of MouseEvent or if it is a KeyboardEvent.

const button = document.getElementById('mouse');

button.addEventListener('mousedown', (e) => {
  if (e instanceof MouseEvent) {
    console.log('a mouse event');
  }
});

const inputField = document.getElementById('keyboard');

inputField.addEventListener('keydown', (e) => {
  if (e instanceof KeyboardEvent) {
    console.log('a keyboard event');
  }
});
<button id="mouse">MouseButton</button>
<input id="keyboard">

about 4 years ago · Juan Pablo Isaza Denunciar

0

Using the event.detail allow you to determine if the event was a keypress or mouse event

if (event.detail === 0) {
    // keypress event
} else {
    // mouse event
}

Read more here - https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail

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