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

364
Views
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 answers
Answer question

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 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!