how to disable github hotkeys/keyboard shortcuts

通过Tampermonkey脚本实现禁用GitHub网站上的键盘快捷键功能。该脚本可在指定网站上运行,阻止网站劫持常用快捷键,适用于希望完全控制键盘操作的用户。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Tampermonkey, The chrome app, is able to achieve this. The script is as following.

// ==UserScript==
// @name           Disable keyboard shortcuts at github
// @description    Stop websites from highjacking keyboard shortcuts
//
// @run-at         document-start
// @include        *github.com*
// @grant          none
// Disable keyboard shortcuts on GitHub? - Web Applications Stack Exchange
// https://webapps.stackexchange.com/questions/51256/disable-keyboard-shortcuts-on-github
// where to find keycodes
// JavaScript Event KeyCodes
// http://keycode.info/
// ==/UserScript==

keycodes = [83] // Keycode for 's', add more keycodes to disable other key captures

document.addEventListener('keydown', function(e) {
//    alert(e.keyCode); //uncomment to find out the keycode for any given key
    if (keycodes.indexOf(e.keyCode) != -1)
    {
        e.cancelBubble = true;
        e.stopImmediatePropagation();
    }
    return false;
});

step by step

create a new script

这里写图片描述

paste the script

The previous scrip just disable the key s.
这里写图片描述

save the script

After saving the script and refreshing the github page, the keyboard shortcut s in github is disabled.

ref

Disable keyboard shortcuts on GitHub? - Web Applications Stack Exchange
https://webapps.stackexchange.com/questions/51256/disable-keyboard-shortcuts-on-github

JavaScript Event KeyCodes
http://keycode.info/

设置Chrome的自定义键盘快捷键(浏览至chrome:// extensions / shortcuts)。 此扩展程序增加了为Chrome设置25种不同的自定义键盘快捷键的功能。 没有此扩展程序,Chrome将无法更改或覆盖任何默认键盘快捷键。 根据设计,此扩展程序完全不需要任何其他Chrome权限。 一切都在Chrome中本地执行,因此不需要访问任何网站或数据。 所有25个键盘快捷键设置都是可选的,可以随时更改。 Chrome扩展程序当前限制为默认的4个“ suggested_key”。 前四个快捷方式具有默认值(可以更改),但是您需要为所需的任何其他快捷方式设置值。 可以在chrome:// extensions / shortcuts上更改所有键盘快捷键。 您可以通过地址栏或单击“键盘快捷方式”扩展程序图标导航到那里。 可以设置的键盘快捷键列表:选择上一个选项卡选择下一个选项卡向左移动当前选项卡向右移动当前选项卡打开Chrome书签(chrome:// bookmarks)打开Chrome下载(chrome:// downloads)打开扩展(chrome://扩展程序)打开扩展程序快捷方式(chrome:// extensions / shortcuts)打开Chrome标志(chrome:// flags)打开Chrome帮助(chrome:// help)打开Chrome历史记录(chrome:// history)打开Chrome设置(chrome: //设置)关闭当前标签页新建标签页从内存中卸载标签页复制当前标签页回到上一页前进至下一页将当前标签页移至第一页将当前标签页移至最后一页静音/取消静音当前标签页固定/取消固定当前标签页重新加载标签页新窗口新隐身窗口图标设计:Freepik从www.flaticon.com制作的扩展图标 支持语言:English
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值