Electron capture mouse events when window is not focused
Asked Answered
C

1

6

Is there a way to capture mouse events like hover and click even when Electron window is not focused? So that my buttons' hover/click effects still work?

Right now, I need to first switch to the Electron window either by clicking or alt-tabbing for the mouse events to be captured.

I'm fairly new to js and electron and I can't seem to find anything on this. But since it works with Atom editor, I'm assuming its possible?

Do I need additional module like mentioned in this post for capturing keyboard events: Atom Electron capture all keyboard events even when app is unfocused?

Thanks! Appreciate any help.

Calender answered 26/7, 2019 at 17:53 Comment(0)
S
8

When creating a new Electron window using new BrowserWindow, it is possible to have mouse click events captured even when the window is not focused by adding:

acceptFirstMouse: true

to the BrowserWindow options.

As for capturing mouse hover events, I'm afraid this is not possible out of the box.

Schroth answered 26/7, 2019 at 20:25 Comment(3)
Thanks! That works perfectly. I'm guessing for hovering I may need to capture global mouse events and focus the window somehow?Calender
This is only for Mac.Bloomers
And for Linux and Windows?Unpeople

© 2022 - 2024 — McMap. All rights reserved.