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

129
Vistas
using Shift + Enter key to run a function

I'm kind of new to JS, I have searched the internet and I haven't got what I'm looking for, I want to run a function if the keys Shift and Enter were pressed, like a shortcut, I have tried this but I think I killed JS with this code

document.addEventListener('keypress', function (e) {
    if (e.key === 'Enter' + 'Shift') {

       console.log("test");
    }
});

anything would be helpful, thanks.

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

0

You can use e.shiftKey to see if shift is being pressed.

document.addEventListener('keypress', function(e) {
  if (e.key === 'Enter' && e.shiftKey) {
    console.log("test");
  }
});

about 4 years ago · Juan Pablo Isaza Denunciar

0

This is a pretty expandable solution because you can create shortcuts for many different keys.

const keysDown = {};
document.addEventListener('keydown', ({ key }) => {
  keysDown[key] = true;
  if (keysDown.Shift && keysDown.Enter) console.log("test");
});
document.addEventListener('keyup', ({ key }) => {
  keysDown[key] = false;
});

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