admin管理员组

文章数量:1400095

I am building an application using JavaScript, node.js, and Electron.

Part of this application is designed to lock the puter 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 puter without having been authenticated).

Any suggestions would be appreciated.

I am building an application using JavaScript, node.js, and Electron.

Part of this application is designed to lock the puter 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 puter without having been authenticated).

Any suggestions would be appreciated.

Share Improve this question edited Jul 17, 2017 at 10:40 toastrackengima 8,7914 gold badges53 silver badges62 bronze badges asked Jul 17, 2017 at 8:00 Javi PalaciosJavi Palacios 1211 gold badge3 silver badges10 bronze badges 4
  • What about other keyboard shortcuts, i.e. ctrl+alt+delete? This does not seem like a secure way to lock a puter. – toastrackengima Commented Jul 17, 2017 at 8: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 Commented Jul 17, 2017 at 8: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. – toastrackengima Commented Jul 17, 2017 at 8:18
  • github./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 – toastrackengima Commented Jul 17, 2017 at 8:25
Add a ment  | 

3 Answers 3

Reset to default 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

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 piled it into exe and then when ever i wants block user using Alt+Tab i am running that script using node mand

  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

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

本文标签: javascriptDisable keyboard shortcuts AltTab in electron applicationStack Overflow