Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda