Reputation: 121
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.
Upvotes: 4
Views: 10219
Reputation: 1079
Okay i had the same issues. as far as i can remember in early electron version we could do this without any problems but not it's not working in new version i don't know the reason. in kiosk
mode also this is not working we can change windows using Alt+Tab
in windows but kiosk
working in mac OS where it blocking all the Command+Tab
function witch Switching between windows.
so as a solution in windows i had use alternative method. what i did is i have written a python code and compiled it into exe
and then when ever i wants block user using Alt+Tab
i am running that script using node command
function execute() {
var exePath =process.platform === "win32"? path.resolve(__dirname, './runner.exe'):null;
runner = child.execFile(exePath, function(error, stdout, stderr){
if (error !== null) {
runner.kill('SIGKILL');
}
});
};
Killing the task when app close
if (process.platform !== 'darwin') {
child.exec(`taskkill -F -T -PID ${runner.pid}`);
kill(runner.pid, 'SIGKILL',(err)=>{
app.quit();
});
}
Python Code
import keyboard
keyboard.add_hotkey("alt + tab", lambda: None, suppress =True)
keyboard.wait()
and that was it i am using kiosk
when i am using Mac or Linux and when i am in windows i am running my exe where it will block Alt+Tab
Upvotes: 1
Reputation: 5322
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
Upvotes: 2
Reputation: 1376
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.
Upvotes: 0