Global shortcuts for windows applications made by electron are blocked by other programs?
1, use electron to make a gadget, want to press a specific key to trigger the behavior of the gadget in a full-screen game;
2. In practice, it is found that in the game, shortcut keys are all blocked, keys do not respond, and it is normal to use other software such as player and browser;
3, how to bypass the screen
4. https://codeshelper.com/a/1190000008529973
method used for shortcut key registration
you can view the official document: https://electronjs.org/docs/a.
.
part of the document is excerpted as follows:
< hr >
the globalShortcut module has the following methods:
globalShortcut.register (accelerator, callback)
- accelerator Accelerator
- callback Function
Register the global shortcut key for accelerator. The callback function is called when the user presses a registered shortcut key.
if the shortcut is already used by another application, the callback function will not be triggered. This feature is defined by the operating system because the operating system does not want the global shortcuts of multiple programs to conflict with each other.
- globalShortcut.isRegistered (accelerator)
- accelerator Accelerator
Returns Boolean-indicates whether the accelerator global shortcut has been successfully registered
this call returns false when the shortcut key is already registered by another application. This feature is defined by the operating system because the operating system does not want the global shortcuts of multiple programs to conflict with each other.
globalShortcut.unregister (accelerator)
Log out of the global shortcut key for accelerator.
globalShortcut.unregisterAll ()
unregister all global shortcuts (clear the application's global shortcuts).
< hr >
you can see why it is invalid from the documentation, and Electron also provides a globalShortcut.isRegistered method to determine whether the shortcut key works. If it does not take effect, you can remind the user to change the shortcut key or trigger it with the mouse.