Disable keyboard shortcuts Alt + Tab in electron application

Viewed 8068

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.

3 Answers

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.

KiosK

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

Related