2

I am not able to disable or change the working of these keyboard shortcuts in Electron.

ctrl+alt+delete and alt+F4

Below I have mentioned the 2 different codes for make this change.


const { app, BrowserWindow, globalShortcut, path, url} = require('electron')

app.on('ready', () => {
  const ret = globalShortcut.register('alt+f4', function () {
    win.show()
  })
})

{
    role: 'help',
    submenu: [
        {
            label: 'Reload', 
            accelerator: 'Alt + F4',
            click: function (item, focusedWindow) {
                focusedWindow.reload();
            } 
        }
    ]
}
guneet Singh
  • 21
  • 1
  • 4
  • 1
    Possible duplicate of [Disable Ctrl-Alt-Del and shutdown for kiosk](https://stackoverflow.com/questions/4234242/disable-ctrl-alt-del-and-shutdown-for-kiosk) – OliverRadini Mar 22 '19 at 10:24
  • Thanks but we have used ElectronJS. – guneet Singh Mar 22 '19 at 12:15
  • First set your BrowserWindow option to `closable: false` this should prevent 'Alt+F4' – Leonardo Buscemi Mar 22 '19 at 16:37
  • Hi Leonardo, thanks for your help but this is not working with my windows app.. below I have mentioned the code: ** function createWindow () { // Create the browser window. win = new BrowserWindow({ width: 1080, height: 720, frame: false, resizable: false, alwaysOnTop:true, closable:false })** – guneet Singh Mar 23 '19 at 11:04

2 Answers2

1

You can disable it by preventing the keydown event on renderer process

window.addEventListener('keydown', (e) => {
    const { key, altKey } = e;
    if (key === 'F4' && altKey) {
        e.preventDefault();   
    }
});
MichaelS
  • 7,023
  • 10
  • 51
  • 75
1

Try to use below code for alt+f4:

 window.webContents
 .on("before-input-event",
   (event,input)=>
      { 
        if(input.code=='F4'&&input.alt) 
           event.preventDefault();
      }
  );
phoenixstudio
  • 1,776
  • 1
  • 14
  • 19
Om..
  • 11
  • 2