Disable Chrome developer tools ⌘-[0-9] keyboard shortcuts?

寵の児 提交于 2020-01-02 05:29:09

问题


Is it possible to disable the ⌘-[0-9] keyboard shortcuts in Chrome's developer tools? It's frustrating to accidentally hit them when I intend to switch tabs (ex, when I hit ⌘-1 because I want to switch to the first tab, but instead being taken to the developer tools "Elements" panel).


回答1:


Update: This feature has landed in Chrome 28.

  1. Open the devtools.
  2. Click on the Gears icon in the bottom-right corner
  3. Select the General tab
  4. Use the checkbox before "Enable Ctrl + 1-9 shortcut to switch panels" to toggle the preference. This option is found in the bottom-right corner of the Settings -> General tab.

Previous answer, which shows how to easily change the source code of your devtools.

There's no preference or flag to change the shortcuts, so you either have to edit the source code and build Chrome yourself, or change one byte in resources.pak.

  1. First, locate resources.pak. This archive (format described here) contains several static files. resources.pak is located in the following directory:

    • OS X 10.7.3: /Applications/Google Chrome.app/Contents/Versions/26.0.1410.65/Google Chrome Framework.framework/Resources/resources.pak
    • Linux (ArchLinux): /usr/lib/chromium/resources.pak
    • Windows XP: %AppData%\..\Local Settings\Application Data\Google\Chrome\26.0.1410.65\resources.pak
    • Windows Vista/7/8: %LocalAppData%\Google\Chrome\26.0.1410.65\resources.pak

    If you cannot find the file at the specified path, use your common sense. Adjust the version, Chrome/Chromium for example. Locate the Chrome executable, and find resources.pak close to it.

  2. Create a back-up of resources.pak in case you mess up.

  3. Open resources.pak (use vim or any other hex editor).
  4. Find _keyDown:, and move a few lines forward (see below). Change ! to ~. What does this do? For all given inputs, ~value will return a negative number, which is truthy, so the _keyDown: function always ends early.

I've confirmed that the Ctrldigit shortcut is disabled in Chrome/Chromium on Linux/Mac/Windows by following these steps.

What could go wrong?

  • You trashed some bytes, e.g. by using Notepad to save resources.pak.
  • You did not edit one byte, but added/removed a byte. Remember, the resource's size is fixed!

In any of these cases, the developer tools will show up as "Not found". Chrome itself is still usable though: Sites can be browsed. If you forgot to make a backup at step 3, re-installing Chrome will fix any issues.


For future reference, part of the source code (source with comments at InspectorView.js):
(in the boldfaced line, replace ! with ~)

_keyDown: function(event)
{
if (!WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event))
return;


if (!event.shiftKey && !event.altKey && event.keyCode > 0x30 && event.keyCode < 0x3A) {
var panelName = this._panelOrder[event.keyCode - 0x31];
if (panelName) {
this.showPanel(panelName);
event.consume(true);
}
return;
}


来源:https://stackoverflow.com/questions/15914851/disable-chrome-developer-tools-0-9-keyboard-shortcuts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!