• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

118
Views
¿Cómo puedo presionar varios botones html a la vez en javascript?

Puedo hacer clic en los botones de flecha en la página web, pero no se pueden leer varios botones al mismo tiempo. Si hago clic en las teclas 37 y 39, no funciona, pero solo funciona cuando hago clic en las teclas 37. Lo mismo ocurre con otras teclas, ¿cómo puedo controlar más de un botón al mismo tiempo?

 const handleArrowButtonMouseDown = function() { $('button').on('mousedown touchstart', (e) => { e.preventDefault(); if(state.arrowPressed) return; let direction = $(e.target).closest('button').attr('id'); state.setArrowPressed(direction); state.setRobotCommand(); }); }; const handleArrowButtonMouseUp = function() { $('button').on('mouseup mouseleave touchend', endCurrentOperation); }; const handleArrowKeyDown = function() { $(document).keydown((e) => { if(state.arrowPressed) return; switch(e.which) { case 37: state.setArrowPressed('left'); break; case 38: state.setArrowPressed('up'); break; case 39: state.setArrowPressed('right'); break; case 40: // down state.setArrowPressed('down'); break; default: return; } e.preventDefault(); state.setRobotCommand(); }); }; const handleArrowKeyUp = function() { $(document).keyup((e) => { if (e.which === 37 && state.arrowPressed !== 'left') return; if (e.which === 38 && state.arrowPressed !== 'up') return; if (e.which === 39 && state.arrowPressed !== 'right') return; if (e.which === 40 && state.arrowPressed !== 'down') return; endCurrentOperation(); }); };
almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hay una forma, pero no es safe confiar en ella, ya que no puede detectar si una clave está actualmente inactiva en JavaScript.

El siguiente ejemplo solo funciona con Shift + Número. Es más cercano a lograr cuando se presionan ambas teclas.

 window.addEventListener("keydown", function (event) { if (event.shiftKey) { if (/\d/.test(event.code)){ console.log("SHIFTKEY + Number:"+event.code); } } }, true)

Tal vez pueda repetir el mismo inicio de sesión en su código.

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error