问题
I am building an application using JavaScript, node.js, and Electron.
Part of this application is designed to lock the computer until the user authenticates themselves.
This works, however I need to make my application disable the alt + tab keyboard shortcut, as currently the user can use this to skip over my lock page (and thus be able to use the computer without having been authenticated).
Any suggestions would be appreciated.
回答1:
You could turn on kiosk mode for the window which makes it full screen and always on top so you can't go to another application.
You could also make the window transparent and position the login in the middle of the screen so it appears as if there is one window in the middle of the screen but you can't click on other areas of the screen.
To handle for Alt+F4 you can use the window.onbeforeunload
event or call event.preventDefault()
in the close
event.
https://electron.atom.io/docs/api/browser-window/#event-close
回答2:
Have you seen the electronJS accelerators? I would take a look at the documentation on that, as well as the windows shortcuts documentation. In theory, you could map a custom function to the alt + tab
command sequence and just console log
or return;
out of it. Something similar is discussed here in the electron forums.
Alternatively, you could modify the registry as mentioned in the link provided by @Toastrackenigma. A discussion on this is found in the electron github page.
Either way, I would be really careful in what you are doing, as modifying a user's shortcuts or registry will likely cause issues on the end user's OS.
来源:https://stackoverflow.com/questions/45138838/disable-keyboard-shortcuts-alt-tab-in-electron-application