用 defaults 提高键盘按键连发速度

通过 InitialKeyRepeat 和 KeyRepeat 两个键,让键盘连发比系统设置里的滑块更快。

macOSmacOS终端defaults 偏好设置键盘中风险
运行 defaults write NSGlobalDomain InitialKeyRepeat -int 15 && defaults write NSGlobalDomain KeyRepeat -int 2,然后注销并重新登录即可生效。

01命令

命令
$ defaults write NSGlobalDomain InitialKeyRepeat -int 15 && defaults write NSGlobalDomain KeyRepeat -int 2 && echo 'Log out and back in to apply.'

02作用说明

InitialKeyRepeat 表示按住多久后开始连发(单位约 15 毫秒),KeyRepeat 表示连发的间隔。系统设置里的滑块有下限,而 defaults 可以写入更小的数值:-int 15(约 225 毫秒延迟)配合 -int 2(约 30 毫秒一次)会让打字和终端操作明显更跟手。修改需要注销重登才生效,删除这两个键即可恢复系统默认。

03风险

风险中风险
!注意: KeyRepeat 设成 0 或 1 时连发极快,笔记本键盘上可能难以控制,建议先小步调整。

04撤销

撤销
$ defaults delete NSGlobalDomain InitialKeyRepeat; defaults delete NSGlobalDomain KeyRepeat

05来源

  • macOS defaults - read, write and delete macOS user defaults
    SS64 · technical · 2026-09-17
    依据: Documents `defaults write domain key -int value` — '-bool[ean]', '-int[eger]', '-float', '-string' value types for writing preference keys; the page also shows deleting keys with `defaults delete`.
  • macOS setup dotfiles (.macos)
    mathiasbynens/dotfiles (GitHub) · community · 2026-09-17
    依据: Sets the same keys verbatim: 'defaults write NSGlobalDomain KeyRepeat -int 1' and 'defaults write NSGlobalDomain InitialKeyRepeat -int 10' to speed up key repeat beyond the UI limits.

最后验证: 2026-09-19 · 分类: 系统与设置

06相关方案