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

198
Visualizações
Javascript: loop until CTRL+C is pressed

How can I make a snippet of code loops until CTRL+C is pressed?

I saw from this thread that the indicated snippet of code loops until key a is pressed.

How to make it loop until CTRL+C is pressed ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

By combining the indicated thread with this one, here is a way to do it

// add the event listener to catch the pressing of CTRL+C

document.body.addEventListener("keydown",function(e){

    e = e || window.event;
    var key = e.which || e.keyCode; // keyCode detection
    var ctrl = e?.ctrlKey || (key === 17); // ctrl detection

    // if CTRL+C is pressed, stop the loop
    if ( key == 67 && ctrl ) {
        window.clearInterval(interval);

        console.log("Ctrl + C was pressed on the browser page (while this one was active).");
        console.log("Loop ends!");     
    }

},false);


// define the time interval that elapses between the end and the beginning of the loops
var x_milliseconds = 1000; // milliseconds

// run a function containing the loop commands, every x_milliseconds
var interval = setInterval(function() {
    console.log("The code is looping!");
}, x_milliseconds);

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