Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
¿Cómo detectar si el evento que se genera pertenece a Keyboard, Pointer o Form Event?

He desarrollado una aplicación que registra los eventos y los reproduce. Para eso, necesito identificar qué tipo de evento se está generando porque los eventos de mouse, teclado y formulario se comportan de manera diferente entre sí.

En este momento estoy tratando de usar: e instanceof KeyboardEvent pero esto no parece estar funcionando. ¿Cuál es la mejor manera de identificar a qué familia de eventos pertenece?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Un ejemplo básico para un evento de mouse y teclado. Solo tiene que agregar un eventListener a su elemento dom deseado. Y luego debe verificar si el evento desencadenado e es una instancia de MouseEvent o si es un 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 Report

0

El uso de event.detail le permite determinar si el evento fue un evento de pulsación de tecla o mouse

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

Lea más aquí: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/detail

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!