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

144
Vistas
use the same key in both render and main process electron?

I am recently learning electron I have encountered a problem that I want to listen ESC in both process,

In Main process,

menu.append(new MenuItem({
    label: "Hide on Escape",
    visible: false,
    accelerator: "Escape",
    click: (item, window, event) => {
      if (window.isVisible()) {
        window.hide();
      }
    }
}))

In Render Process,

// on Key press Handler
const onKeyDownHandler = (event: React.KeyboardEvent) => {
    if (isContentEditable && event.key === "Enter") {
      applyContentEditable();
    } else if (event.key === "Enter") {
      onSelected && onSelected(pair);
    } else if (event.key === "Delete") {
      onDelete && onDelete(pair);
    } else if (event.key === "F2") {
      setIsContentEditable(true);
    } else if (event.key === "Escape") {
      resetContentEditable(); // Stop Renaming and get back to default
    }
}

But this didn't work the window hides before the render process. How can I Stop hide when it is listened by Render Process

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

0

There is an event.stopPropagation() method which prevents further propagation/calls on the same event Docs

And there is event.preventDefault() which can be used to stop default handling Docs

I still don't quite fully understand your setup and what you are try to achieve.
Another solution is to stop listening on the escape key in the main process at all. Only listen in the render process and then pass the event manually to the main process in case you want to take some action there as well (or the other way around, depending on what makes more sense for you).
For this passing you are probably looking at the electron ipcMain module https://www.electronjs.org/docs/latest/api/ipc-main

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