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

361
Vistas
How can I hit multiple html buttons at once in javascript?

I can click the arrow buttons on the web page, but multiple buttons cannot be read at the same time.If I click on 37 and 39 keys it does not work but only when I click on 37 keys it works. Same goes for other keys, how can I control more than one button at the same time?

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();
  });
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There is one way, but it's not safe to rely on, since you cannot detect if a key is currently down in JavaScript.

The example below works only with Shift + Number. It's closest to achieve when both keys are pressed.

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

Maybe you can repeat the same login to your code.

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