12

I've been getting into a few Electron projects and I am trying to figure out how you could listen for any keypresses or and track mouse movement when the app is in the background. I am using the menubar plugin so the app is still running in the background.

I tried using the global-shortcut API but it looks like that is for shortcuts only and you can't register individual keystrokes. I've also looked over the API and have yet to find an event for keystrokes and mouse movements outside the app's main screen.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
cameronmoreau
  • 407
  • 1
  • 6
  • 14

1 Answers1

6

This is outside of the realm of normal use-cases for an electron application. In order to do this you would need to develop a native module that calls into the corresponding native functions of the operating system.

For example on windows: C++ Win32 keyboard events

Making native addons for node: https://nodejs.org/api/addons.html

FYI, Native addons are very hard.

Community
  • 1
  • 1
justin.m.chase
  • 13,061
  • 8
  • 52
  • 100