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

122
Vistas
How to create an event listener for the keyboard event 'ctrl + q' without it closing the browser window?

Problem summary: The eventListener for the 'keydown' event is supposed to perform a function when the 'ctrl' + 'q' keys are pressed simultaneously, similar to the keyboard shortcuts for search boxes on many popular websites these days. Of course, when I press both keys on my computer, it tries to close the window.

How do I prevent the operating system's default event for the keyboard shortcut from firing when this website is opened in a tab? Any tips on how I can implement the shortcut functionality of this key combination?

Current code (examplified):

let searchBoxIsOpen = false;

document.addEventListener('keydown', (event) => {
  
  event.stopPropagation();
  event.preventDefault();
 
  if (
    event.ctrlKey
    && event.keyCode == 81
    && !(event.shiftKey || event.altKey || event.metaKey)
     ) {
    
    if (!searchBoxIsOpen) {
      searchBoxIsOpen = true;
      console.log("alert");
      return;
    }
    
    console.log("delert");
    return;
    
  }
  
});
about 4 years ago · Juan Pablo Isaza
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