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

97
Vistas
combination of buttons in event OnKeydown

I need to set up combination of buttons in input form of my react app.

  1. "CTRL + "ArrowUp"
  2. "ArrowUp"

My code is something like this.

//Form

<input onKeyDown={keyHandler}/>

//handler

const keyhandler = (e) => {

if(e.key === "ArrowUp") {//do something}

if(e.key === 'ArrowUp' && e.getModifierState("Control")) {//do another thing}

The problem is when event fired with combination, first 'if' also true. How separate "ArrowUp" and "ArrowUp" with ctrl button?

I also try like this (but it didn't help):


if(e.key === 'ArrowUp' && event.ctrlKey){ //do another thing}

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

0

Just following your logic,

  if (Control is pressed) {
    if (ArrowUp is pressed) {
        // both are pressed
    }
  } else {
    if (ArrowUp is pressed) {
        // only arrow up is pressed
    }
  }
about 4 years ago · Juan Pablo Isaza Denunciar

0

I solved my problem by using this one.

if(!e.getModifierState('Control')){
 if(e.key == 'ArrowUp'){ 
  //single button action
  }
}
if(e.key == "ArrowUp" && e.getModifierState("Control")){
 //combo buttons action
}
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