4

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.

Toastrackenigma
  • 7,604
  • 4
  • 45
  • 55
Javi Palacios
  • 121
  • 3
  • 10
  • What about other keyboard shortcuts, i.e. `ctrl`+`alt`+`delete`? This does not seem like a secure way to lock a computer. – Toastrackenigma Jul 17 '17 at 08:10
  • Well, I'd really like to disable all the keyboard shortcuts, just offering the Alt + Tab as an example because it's the one that gives me problems right now. – Javi Palacios Jul 17 '17 at 08:13
  • Another one for you would be `alt`+`f4`. This is the sort of thing that apps like Cryptolocker try to do, so even if your app is legitimate, I don't think you're going to have much luck with some of these, as the OS is designed to help ensure that the user never ends up in a scenario where they are locked out by a malicious application. At best, you'd need to use a more low-level solution, like C, to actually override the OS - I don't imagine that electron (which just runs webpages as native apps) will have the power to do this. – Toastrackenigma Jul 17 '17 at 08:18
  • https://github.com/electron/electron/issues/2156 - there, `ctrl`+`alt`+`delete` can't be caught. Hopefully some of the code on that page helps solve the `alt`+`tab` issue for you though, and then you can probably pull off some registry magic to solve the `ctrl`+`alt`+`delete` problem, like the guy at the bottom of that post did :D – Toastrackenigma Jul 17 '17 at 08:25

3 Answers3

2

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

Joshua
  • 5,032
  • 2
  • 29
  • 45
1

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

Thalinda Bandara
  • 1,039
  • 1
  • 11
  • 27
0

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 logor 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.

unseen_damage
  • 1,346
  • 1
  • 14
  • 32