#Looking to add custom functionality to CTRL+SHIFT+I

9 messages · Page 1 of 1 (latest)

sullen token
#

Looking to mimic something similar to what Discord has implemented. Basically, when someone attempts to open DevTools, I will do a check to determine if they have the permissions to access DevTools. If they do, I want to open DevTools. Otherwise, I just want to do nothing, or maybe do a popup. Currently my issue is I cannot seem to stop the default behavior by using the onkeyup event. Is there a better way to do this? Or something build in by default? I am using a brand new Electron Project with ReactJS (Typescript).

full badger
#

i think the default keybind of ctr+shift+i is an accelerator (shortcut) from the default Menu. maybe you could set your own Menu and have ctrl+shift+i just run your custom logic before opening the dev tools

sullen token
river marsh
#

Do you wanna keep the default electron menu? You could remove that and instead use app before-input-event and when f12 is pressed toggle the devtools. That gives you full control on what you wanna do when f12 is pressed

#

That is how i did it

sullen token
river marsh
#
  const browserWindow = new BrowserWindow(...);

  browserWindow.removeMenu();

  browserWindow.webContents.on('before-input-event', (_, input) => {
    if (input.type === 'keyDown' && input.key === 'F12') {
      browserWindow.webContents.openDevTools({ mode: 'detach' });
    }
  });
#

a older way of doing it was setting the menu to null. just in case you stumble on that later. but the new method is more clear i think