禁用 Jupyter 键盘快捷键

Disable Jupyter Keyboard Shortcuts

我的一个 Jupyter 笔记本使用了一个 html <input> 标签,它需要输入用户输入,但每当我在文本框中输入时,命令模式键盘快捷键就会激活。

是否可以关闭单个单元格或笔记本的键盘快捷键?

您可以将此行复制粘贴到您的 custom.js:

$([IPython.events]).on("app_initialized.NotebookApp", function () {
    ...
    // Starting from this line, replace 'Shift-k' with whatever 
    // shortcut you're trying to remove.
    IPython.keyboard_manager.command_shortcuts.remove_shortcut('Shift-k')
    ...
});

或者您希望删除的任何快捷方式。

来源: http://akuederle.com/customize-ipython-keymap/

如果你想要样品 custom.jsthis is mine 在我的 github。

您可以使用Jupyter.keyboard_manager.disable()暂时禁用快捷方式,然后使用Jupyter.keyboard_manager.enable()再次激活。

根据the current 'Customize keymaps' docuemntation, this can now be done using the ~/.jupyter/nbconfig/notebook.json file more simply than hlin117的回答:

For example, to unbind the shortcut to split a cell at the position of the cursor (Ctrl-Shift-Minus)use the following:

// file ~/.jupyter/nbconfig/notebook.json
{
  "keys": {
    "edit": {
      "unbind": [
        "Ctrl-Shift-Minus"
      ]
    },
  },
}