Karabiner-Elements|解决 Mac 键盘数字键自动连击:禁用数字键,按住 fn 才输入(以 A1314 为例)

简短结论:Apple A1314 键盘有几个数字键会随机自动连击,清洁键帽没用,应该是电路板故障。用 Karabiner-Elements 给这块键盘加一条规则:平时拦截数字键,按住 fn 时才放行。这样既不会误触,需要输数字时按住 fn 即可。

问题现象

2009 年制的 Apple A1314 键盘,经常有两三个数字键会随机自动连击,重复输入。打开键帽清洁后没有改善,判断为电路板故障。

解决思路

硬件修不了,就用软件绕过:

  1. 平时拦截主键盘区的数字行(1–0、-、=)。
  2. 按住 fn 时才放行这些键。

规则只对这块键盘生效(按 Vendor ID 和 Product ID 限定),MacBook 自带键盘和其他外接键盘不受影响。

下载 Karabiner-Elements

官网下载链接。支持的系统以官网为准,写本文时官网列出 macOS 26 Tahoe、15 Sequoia、14 Sonoma、13 Ventura。

第一步:安装并授予权限

下载并安装 Karabiner-Elements。

安装完成后,在 Mac 的系统设置里按提示允许 Karabiner 需要的权限(具体选项以屏幕提示为准)。

Mac 系统设置中允许 Karabiner-Elements 的权限

Mac 系统设置中允许 Karabiner-Elements 的权限

Mac 系统设置中允许 Karabiner-Elements 的权限
Mac 系统设置中允许 Karabiner-Elements 的权限
Mac 系统设置中允许 Karabiner-Elements 的权限
Mac 系统设置中允许 Karabiner-Elements 的权限

第二步:确认键盘的设备 ID

打开 Karabiner → Devices,找到那块键盘,记下:

  • Vendor ID:1452
  • Product ID:599

注意要看的是外接键盘的 ID,不是 MacBook 自带的键盘。

Karabiner-Elements 的 Devices 页面,显示 A1314 的 Vendor ID 和 Product ID

第三步:创建规则文件

用 TextEdit 创建 Karabiner 规则文件
  1. 打开「文本编辑」(TextEdit),按 Shift + Command + T 切换成纯文本模式。
  2. 粘贴下面的 JSON。
  3. 如果你的 ID 和上面不同,用「查找和替换」(Option + Command + F)把 1452 和 599 分别替换成你的 Vendor ID 和 Product ID,会一次替换全部。
  4. 文件 → 存储,文件名输入 a1314_fn_numbers.json,位置选「桌面」。如果保存后文件名变成了 .json.txt,把 .txt 去掉。
JSON
{
  "title": "A1314 (VID1452 PID599) Numbers require fn",
  "rules": [
    {
      "description": "A1314 only: 1-0, -, = work only while holding fn (otherwise disabled)",
      "manipulators": [
        {"type": "basic", "from": {"key_code": "fn", "modifiers": {"optional": ["any"]}}, "to": [{"set_variable": {"name": "a1314_fn_pressed", "value": 1}}], "to_after_key_up": [{"set_variable": {"name": "a1314_fn_pressed", "value": 0}}], "conditions": [{"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "1"}, "to": [{"key_code": "1"}], "conditions": [{"type": "variable_if", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "1"}, "to": [{"key_code": "vk_none"}], "conditions": [{"type": "variable_unless", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "2"}, "to": [{"key_code": "2"}], "conditions": [{"type": "variable_if", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "2"}, "to": [{"key_code": "vk_none"}], "conditions": [{"type": "variable_unless", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "3"}, "to": [{"key_code": "3"}], "conditions": [{"type": "variable_if", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "3"}, "to": [{"key_code": "vk_none"}], "conditions": [{"type": "variable_unless", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "4"}, "to": [{"key_code": "4"}], "conditions": [{"type": "variable_if", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "4"}, "to": [{"key_code": "vk_none"}], "conditions": [{"type": "variable_unless", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "5"}, "to": [{"key_code": "5"}], "conditions": [{"type": "variable_if", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "5"}, "to": [{"key_code": "vk_none"}], "conditions": [{"type": "variable_unless", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "6"}, "to": [{"key_code": "6"}], "conditions": [{"type": "variable_if", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "6"}, "to": [{"key_code": "vk_none"}], "conditions": [{"type": "variable_unless", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "7"}, "to": [{"key_code": "7"}], "conditions": [{"type": "variable_if", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "7"}, "to": [{"key_code": "vk_none"}], "conditions": [{"type": "variable_unless", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "8"}, "to": [{"key_code": "8"}], "conditions": [{"type": "variable_if", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "8"}, "to": [{"key_code": "vk_none"}], "conditions": [{"type": "variable_unless", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "9"}, "to": [{"key_code": "9"}], "conditions": [{"type": "variable_if", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "9"}, "to": [{"key_code": "vk_none"}], "conditions": [{"type": "variable_unless", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "0"}, "to": [{"key_code": "0"}], "conditions": [{"type": "variable_if", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "0"}, "to": [{"key_code": "vk_none"}], "conditions": [{"type": "variable_unless", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "hyphen"}, "to": [{"key_code": "hyphen"}], "conditions": [{"type": "variable_if", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "hyphen"}, "to": [{"key_code": "vk_none"}], "conditions": [{"type": "variable_unless", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "equal_sign"}, "to": [{"key_code": "equal_sign"}], "conditions": [{"type": "variable_if", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]},
        {"type": "basic", "from": {"key_code": "equal_sign"}, "to": [{"key_code": "vk_none"}], "conditions": [{"type": "variable_unless", "name": "a1314_fn_pressed", "value": 1}, {"type": "device_if", "identifiers": [{"vendor_id": 1452, "product_id": 599}]}]}
      ]
    }
  ]
}

规则的逻辑是:按下 fn 时把变量 a1314_fn_pressed 设为 1,松开设为 0;每个数字键有两条规则,变量为 1 时正常输出,变量不是 1 时输出”什么都不做”(vk_none)。

第四步:把规则文件放进 Karabiner 目录

  1. 打开 Finder,按 Shift + Command + G。
  2. 输入 ~/.config/karabiner/assets/complex_modifications,前往。
  3. 把桌面上的 a1314_fn_numbers.json 拖进去。
在 Finder 中前往 Karabiner 的 complex_modifications 目录

第五步:在 Karabiner 中启用规则

打开 Karabiner → Complex Modifications → Add Rule,就能看到刚放进去的规则,点击 Enable。

在 Karabiner 的 Complex Modifications 中启用 A1314 规则
在 Karabiner 的 Complex Modifications 中启用 A1314 规则
在 Karabiner 的 Complex Modifications 中启用 A1314 规则

效果

这块键盘的数字键不再随机连击;需要输入数字时,按住 fn 再按数字键即可。想恢复原样,在 Complex Modifications 里删除这条规则就行。

常见问题

规则添加后没有效果?
先到 Devices 页面确认这块键盘已经被 Karabiner 接管(如果有”Modify events”之类的开关,需要打开),再检查 JSON 里的 Vendor ID 和 Product ID 是否和你的设备一致。

想拦截或放行别的键?
照着规则文件里的格式,复制一对规则,把 key_code 换成对应的键名即可。

会影响其他键盘吗?
不会。每条规则都带有设备条件,只作用于指定 ID 的那块键盘。

更多文章