AppleScript:将 Caps Lock 键切换为 Control 的脚本 [英] AppleScript: Script to switch Caps Lock Key to Control
问题描述
我试图找到解决方案,因为我正在使用 Vim,而且大多数时候我需要将 Caps lock 分配给 Ctrl.有时我希望 Caps Lock 正常工作.我认为 Apple Script 很棒,因为它可以分配给 LaunchBar 操作.
I was trying to find a solution to this because I am using Vim and most of the time I need Caps lock to be assigned to Ctrl. There are times though that I want the Caps Lock working normally. I thought an Apple Script is great as it can be assigned to a LaunchBar action.
我将回答我最终得到的解决方案(通过 GUI 脚本),但如果有人知道一种方法,我会对侵入性较小的解决方案感兴趣......
I will answer with the solution I ended up with (through GUI scripting) but would be interested in a less intrusive solution if someone knows a way...
推荐答案
您可以使用 PCKeyboardHack 将大写锁定更改为 F19.然后将其保存为 private.xml:
You can use PCKeyboardHack to change caps lock to F19. Then save this as private.xml:
<?xml version="1.0"?>
<root>
<item>
<name>caps1</name>
<identifier>caps1</identifier>
<autogen>__KeyToKey__ KeyCode::F19, KeyCode::CAPSLOCK</autogen>
</item>
<item>
<name>caps2</name>
<identifier>caps2</identifier>
<autogen>__KeyToKey__ KeyCode::F19, KeyCode::CONTROL_L</autogen>
</item>
</root>
并使用此脚本切换设置:
And use this script to toggle the settings:
k=/Applications/KeyRemap4MacBook.app/Contents/Applications/KeyRemap4MacBook_cli.app/Contents/MacOS/KeyRemap4MacBook_cli
if $k changed | grep -q ^caps1=; then
$k disable caps1
$k enable caps2
else
$k enable caps1
$k disable caps2
fi
尽管将另一个组合键分配给大写锁定会更容易:
It would be easier to just assign another key combination to caps lock though:
<autogen>__KeyOverlaidModifier__ KeyCode::CONTROL_L, ModifierFlag::FN, KeyCode::CONTROL_L, ModifierFlag::FN, KeyCode::CAPSLOCK</autogen>
这将在按下键时触发,因此对于 fn+control+down 等组合键,您必须在 fn 之前按下 control:
This would be triggered on key down, so you'd have to press control before fn for key combinations like fn+control+down:
<autogen>__KeyToKey__ KeyCode::CONTROL_L, ModifierFlag::FN, KeyCode::CAPSLOCK</autogen>
这篇关于AppleScript:将 Caps Lock 键切换为 Control 的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!