macos 在 Mac OS X 中使用 Caps Lock 作为 Esc
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/127591/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Caps Lock as Esc in Mac OS X
提问by indentation
How do I make Caps Lockwork like Escin Mac OS X?
我如何Caps Lock像Esc在 Mac OS X 中一样工作?
回答by cwd
Edit:As described in this answer, newer versions of MacOS now have native support for rebinding Caps Lockto Escape. Thus it is no longer necessary to install third-party software to achieve this.
编辑:如本答案所述,较新版本的 MacOS 现在原生支持重新绑定Caps Lock到Escape. 因此不再需要安装第三方软件来实现这一点。
Here's my attempt at a comprehensive, visual walk-through answer (with links) of how to achieve this using Seil(formerly known as PCKeyboardHack
).
这是我对如何使用Seil(以前称为PCKeyboardHack
)实现这一目标的全面、直观的演练答案(带有链接)的尝试。
- First, go into the System Preferences, choose Keyboard, then the Keyboard Tab(first tab), and click Modifier Keys:
- 首先,进入System Preferences,选择Keyboard,然后选择Keyboard Tab(第一个选项卡),然后单击Modifier Keys:
In the popup dialog set Caps Lock Keyto No Action
:
在弹出对话框中将Caps Lock Key设置为No Action
:
2) Now, click here to download Seiland install it:
2)现在,点击这里下载Seil并安装它:
3) After the installation you will have a new Application installed ( Mountain Lion and newer ) and if you are on an older OS you may have to check for a new System Preferences pane:
3) 安装后,您将安装一个新应用程序(Mountain Lion 和更新版本),如果您使用的是较旧的操作系统,则可能需要检查新的系统偏好设置窗格:
4) Check the box that says "Change Caps Lock" and enter "53" as the code for the escape key:
4) 选中“Change Caps Lock”框并输入“53”作为转义键的代码:
And you're done!If it doesn't work immediately, you may need to restart your machine.
大功告成!如果它不能立即工作,您可能需要重新启动机器。
Impressed? Want More Control?
印象深刻?想要更多控制?
You may also want to check out KeyRemap4MacBookwhich is actually the flagship keyboard remapping tool from pqrs.org
- it's also free.
您可能还想查看KeyRemap4MacBook,它实际上是来自的旗舰键盘重新映射工具pqrs.org
- 它也是免费的。
If you like these tools you can make a donation. I have no affiliation with them but I've been using these tools for a long time and have to say the guys over there have been doing an excellent job maintaining these, adding features and fixing bugs.
如果您喜欢这些工具,您可以捐款。我与他们没有任何关系,但我已经使用这些工具很长时间了,不得不说那里的人在维护这些工具、添加功能和修复错误方面做得非常出色。
Here's a screenshot to show a few of the (hundreds of) pre-selectable options:
这是显示一些(数百个)预选选项的屏幕截图:
PQRS also has a great utility called NoEjectDelaythat you can use in combination with KeyRemap4MacBookfor reprogramming the Eject key. After a little tweaking I have mine set to toggle the AirPort Wifi.
PQRS 还有一个很棒的实用程序,叫做NoEjectDelay,你可以结合KeyRemap4MacBook使用它来重新编程 Eject 键。稍作调整后,我已设置为切换 AirPort Wifi。
These utilities offer unlimited flexibility when remapping the Mac keyboard. Have fun!
这些实用程序在重新映射 Mac 键盘时提供了无限的灵活性。玩得开心!
回答by rkusa
回答by wim
I wasn't happy with any of the answers here, and went looking for a command-line solution.
我对这里的任何答案都不满意,并开始寻找命令行解决方案。
In macOS Sierra 10.12, Apple introduced a new way for users to remap keys.
在 macOS Sierra 10.12 中,Apple 为用户引入了一种重新映射键的新方法。
- No need to fiddle around with system GUIs
- No special privileges are required
- Completely customisable
- No need to install any 3rd-party crap like PCKeyboardHack / Seil / Karabiner / KeyRemap4MacBook / DoubleCommand / NoEjectDelay
- 无需摆弄系统 GUI
- 不需要特殊权限
- 完全可定制
- 无需安装任何第三方垃圾,如 PCKeyboardHack / Seil / Karabiner / KeyRemap4MacBook / DoubleCommand / NoEjectDelay
If that sounds good to you, take a look at hidutil
.
如果这听起来不错,请查看hidutil
。
For example, to remap caps-lock to escape, refer to the key tableand find that caps-lock has usage code 0x39 and escape has usage code 0x29. Put these codes or'd with the hex value 0x700000000 in the source and dest like this:
例如,将caps-lock重新映射为escape,参考key表,发现caps-lock的使用码为0x39,escape的使用码为0x29。将这些代码或带有十六进制值 0x700000000 的代码放在源和目标中,如下所示:
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}'
You may add other mappings in the same command. Personally, I like to remap caps-lock to backspace, and remap backspace to delete:
您可以在同一命令中添加其他映射。就个人而言,我喜欢将 caps-lock 重新映射到退格键,并将退格键重新映射到删除:
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x70000002A}, {"HIDKeyboardModifierMappingSrc":0x70000002A,"HIDKeyboardModifierMappingDst":0x70000004C}]}'
To see the current mapping:
查看当前映射:
hidutil property --get "UserKeyMapping"
Your changes will be lost at system reboot. If you want them to persist, put them in a script and setup a login hook:
您的更改将在系统重新启动时丢失。如果你想让它们持久化,把它们放在一个脚本中并设置一个登录钩子:
sudo defaults write com.apple.loginwindow LoginHook /path/to/login_script.sh
回答by eelco
It's possible.
这是可能的。
Solution 1
方案一
From an arcticleon TrueAffection.net.
从一个arcticle上TrueAffection.net。
- Download PCKeyboardHack and install it.
- Go to PCKeyboardHack in System Preferences.
- Enable ‘Change Caps Lock' and set the keycode to 53.
- 下载 PCKeyboardHack 并安装它。
- 转到系统偏好设置中的 PCKeyboardHack。
- 启用“更改大写锁定”并将键码设置为 53。
Solution 2
解决方案2
This solution doesn't involve patching the keyboard driver, but gives you a Vim specific solution.
此解决方案不涉及修补键盘驱动程序,而是为您提供 Vim 特定的解决方案。
OS X supports mapping the Caps Lock key to a whole bunch of keys, but you have to do it 'by hand', editting .plist files. The process is described in this article. As addendum to that hint I suggest you first set Caps-Lock to None in the System Preferences, then you only need to change one value in the .plist file. Also, you can of course use the Property List Editor instead of going through the XML conversion steps.
OS X 支持将 Caps Lock 键映射到一大堆键,但您必须“手动”完成,编辑 .plist 文件。该过程在本文中进行了描述。作为该提示的补充,我建议您首先在“系统偏好设置”中将 Caps-Lock 设置为“无”,然后您只需更改 .plist 文件中的一个值。此外,您当然可以使用属性列表编辑器,而无需执行 XML 转换步骤。
The trick is to map the Caps Lock key to the Help key (code 6), which isn't on most keyboards. But if it is, it will be treated as the insert key, which you probably don't use anyway, since you ask about remapping your Caps Lock to prevent stretching your hands ;)
诀窍是将 Caps Lock 键映射到 Help 键(代码 6),这在大多数键盘上都没有。但如果是,它将被视为插入键,您可能无论如何都不会使用它,因为您询问重新映射 Caps Lock 以防止伸手 ;)
You can then map the Help and the Insertkey to Escin vim.
然后,您可以将帮助和Insert密钥映射到Escvim。
map <Help> <Esc>
map! <Help> <Esc>
map <Insert> <Esc>
map! <Insert> <Esc>
This will work for gvim (Vim.app). I didn't get it to work with vim in the Terminal and I haven't tested it with MacVim.
这将适用于 gvim (Vim.app)。我没有让它在终端中与 vim 一起工作,我也没有用 MacVim 测试过它。
So, it's rather a complicated, half-baked solution or installing a third-party piece of hackery. Your pick ;)
所以,这是一个相当复杂的、半生不熟的解决方案或安装第三方黑客。你的选择;)
Edit: Just noticed solution 3, if you're using MacVimyou can use Ctrl, Optionand Commandas Esc. With the System Preferences it's trivial to map Caps Lock to one of those keys.
编辑:只注意到解决方案3,如果您使用的MacVim可以使用Ctrl,Option并且Command作为Esc。使用系统偏好设置将 Caps Lock 映射到这些键之一是微不足道的。
回答by neurosnap
It is now much easier to map the Caps Lockkey to Escwith macOS Sierra.
现在使用 macOS Sierra映射Caps Lock密钥要容易得多Esc。
Open System Preferences → Keyboard.
Click the Modifier Keys button in the bottom right-hand corner.
Click the drop down box next to the hardware key that you'd like to remap, and select Escape.
Click OK and close System Preferences.
打开系统偏好设置 → 键盘。
单击右下角的修饰键按钮。
单击要重新映射的硬件密钥旁边的下拉框,然后选择 Escape。
单击确定并关闭系统偏好设置。
回答by EfForEffort
The only thing I know how to do is to map Caps Lock to Control, or Option, or Command. This can be done via the Keyboard & Mouse pane of System Preferences. Click on "Modifier Keys" on the bottom left and you'll be able to remap Caps Lock, Control, Option, and Command, to any of those.
我唯一知道如何做的是将 Caps Lock 映射到 Control、Option 或 Command。这可以通过系统偏好设置的键盘和鼠标面板来完成。单击左下角的“修饰键”,您将能够将 Caps Lock、Control、Option 和 Command 重新映射到其中任何一个。
@Craig: This suggests that Caps Lock canbe used as a normal -- that is, non-toggle -- key. On my MacBook, since I have re-mapped Caps Lock to Control, the Caps Lock light never lights up. It simply acts like the Control key.
@Craig:这表明 Caps Lock可以用作普通键——即非切换键。在我的 MacBook 上,由于我将 Caps Lock 重新映射到 Control,Caps Lock 灯永远不会亮起。它的作用就像 Control 键一样。
回答by Michael Glass
Seil isn't yet available on macOS Sierra (10.12 beta). As such, I've been using Keyboard Maestro with these settings:
Seil 在 macOS Sierra(10.12 测试版)上尚不可用。因此,我一直在使用具有以下设置的键盘大师:
Credit to this github comment: https://github.com/tekezo/Seil/issues/68#issuecomment-230131664
归功于此 github 评论:https: //github.com/tekezo/Seil/issues/68#issuecomment-230131664
回答by Zxaos
Having tried several of these solutions, I have some notes:
尝试了其中几种解决方案后,我有一些注意事项:
DoubleCommandwill notallow you to swap esc and caps-lock.
DoubleCommand会不会让你掉ESC和大写锁定。
PCKeyboardHackwillallow you to map capslock to escape, but does not have the capability to map escape to capslock. Recent versions will allow you to perform a complete swap by editing both keys.
PCKeyboardHack将允许您映射大写锁定以逃脱,但没有能力将转义映射到大写锁定. 最近的版本将允许您通过编辑两个键来执行完整的交换。
This may or may not be sufficient for your needs (I know it is for mine).
这可能足以满足您的需求,也可能不够(我知道这是我的需求)。
回答by user2581875
In case you don't want to install a third-party app and you really only care about vim inside iTerm, the following works:
如果您不想安装第三方应用程序并且您真的只关心 iTerm 中的 vim,则可以使用以下方法:
Remap CapsLock to Help as described here.
按照此处所述将 CapsLock 重新映射到帮助。
Short version: use plutil or similar to edit ~/Library/Preferences/ByHost/.GlobalPreferences*.plist
, it should look similar to this:
简短版本:使用 plutil 或类似的来编辑~/Library/Preferences/ByHost/.GlobalPreferences*.plist
,它应该类似于:
<key>HIDKeyboardModifierMappingDst</key>
<integer>6</integer>
<key>HIDKeyboardModifierMappingSrc</key>
<integer>0</integer>
Restart! A simple log-out and log-in did not work for me.
重新开始!简单的注销和登录对我不起作用。
In iTerm, add a new key mapping for Help: send hex code 0x1b, which corresponds to Escape.
在 iTerm 中,为 Help 添加新的键映射:发送对应于 Escape 的十六进制代码 0x1b。
I know this is not exactly what was asked for, but I assume the intent of many people looking for a solution like this is actually this more specialized variant.
我知道这并不完全是我们所要求的,但我认为许多寻找此类解决方案的人的意图实际上是这种更专业的变体。
回答by chb
In order to actually swap the escape key with the caps lock key (not just map one to the other) using both PCKeyboardHack and KeyRemap4MacBook, you have to follow the instructions in this thread, mapping the caps lock key to a keycode not used by the keyboard but accounted for by KeyRemap4MacBook (eg. 110). Then, in PCKeyboardHack, select the appropriate option that maps that keycode to escape (in the case of 110, it's "Application Key to Escape"). Here's what your KeyRemap4MacBook preferences should look like (provided you've selected the "show enabled only" checkbox).
为了实际使用 PCKeyboardHack 和 KeyRemap4MacBook 将转义键与大写锁定键(不仅仅是将一个映射到另一个)交换,您必须按照此线程中的说明,将大写锁定键映射到未被使用的键码键盘,但由 KeyRemap4MacBook(例如 110)计算。然后,在PCKeyboardHack中,选择适当的选项,将该键码映射到转义(在110的情况下,它是“应用密钥逃脱”)。这是您的 KeyRemap4MacBook 首选项的外观(前提是您已选中“仅显示已启用”复选框)。
I originally attempted to post this information as an editto cwd's excellent answer, but it was rejected. I encourage anyone who wants to go the route that I describe to first read his/her response.