macos 从 Mac 上的命令行启用/禁用 Fn 键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3446128/
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
Enable/Disable Fn keys from the command line on the Mac
提问by Randall
I hardly ever use the function keys on my macbook pro. I mostly just use them for volume, brightness, etc. Now that I've started playing Starcraft 2 a bunch, I want to use them without having to press the fn key down.
我几乎从不使用 macbook pro 上的功能键。我大多只是将它们用于音量、亮度等。现在我已经开始大量玩星际争霸 2,我想使用它们而不必按下 fn 键。
I want to write a little shell script that will flip the "Use all F1, F2, etc keys as standard function keys" check box. I was thinking I could use the defaults command to change it but I wasn't sure what values to use. This way I don't have to change the the preferences every time I want to play. I can just run the script that'll switch the keys and even launch the game.
我想编写一个小的 shell 脚本来翻转“使用所有 F1、F2 等键作为标准功能键”复选框。我想我可以使用 defaults 命令来更改它,但我不确定要使用什么值。这样我每次想玩时都不必更改首选项。我可以运行脚本来切换按键甚至启动游戏。
Any ideas?
有任何想法吗?
回答by user123444555621
An AppleScript that should do the trick -- taken from http://scriptbuilders.net/files/fn1.1.html, with slight modifications
应该可以解决问题的 AppleScript - 取自http://scriptbuilders.net/files/fn1.1.html,稍作修改
--Check if GUI Scripting is Enabled
tell application "System Events"
if not UI elements enabled then
set UI elements enabled to true
end if
end tell
--Enable/Disable "Use all F1, F2, etc. keys as standard function keys" option in Keyboard & Mouse Preference pane and close System Preferences
tell application "System Events"
tell application "System Preferences"
reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell
click checkbox 1 of tab group 1 of window 1 of application process "System Preferences"
end tell
if application "System Preferences" is running then
tell application "System Preferences" to quit
end if
Tested on MacOS 10.6.4
在 MacOS 10.6.4 上测试
回答by Robert
The command is defaults write -g com.apple.keyboard.fnState
, although I've had problems in the past changing it. I ended up just using an AppleScript. Give it a try.
命令是defaults write -g com.apple.keyboard.fnState
,虽然我在过去改变它时遇到了问题。我最终只使用了 AppleScript。试一试。
defaults write -g com.apple.keyboard.fnState -boolean true
Edit
To elaborate, the problems I've had is that the actual value is changed, but it doesn't actively change the setting in System Preferences nor does the fnState toggle, because the file is only read at boot/login etc. Also, making changes to a config file that's opened by another task sounds like a good way to corrupt the file.
编辑
详细说明,我遇到的问题是实际值已更改,但它不会主动更改系统偏好设置中的设置,也不会切换 fnState,因为该文件仅在启动/登录等时读取。此外,更改由另一个任务打开的配置文件听起来像是破坏文件的好方法。
回答by Gal Bracha
You can install the awsome Karabiner-Elements.
您可以安装令人敬畏的Karabiner-Elements。
Under System Preferences-> Keyboard preferences, make sure "Use all F1, F2, etc. keys as standard function keys" is checked as a perquisites.
在系统首选项-> 键盘首选项下,确保选中“将所有 F1、F2 等键用作标准功能键”作为必要条件。
- Open KeyRemap4MacBook preferences.
- Navigate to "Pass Through Mode" option.
- Check the 'Change Fn+Escape to toggle "Pass Through Mode"'
- Open "Change F1..F19 Key" and check the "Macbook Pro" or "Macbook Air" option choosing your correct mac type.
- 打开 KeyRemap4MacBook 首选项。
- 导航到“通过模式”选项。
- 选中“更改 Fn+Escape 以切换“通过模式””
- 打开“更改 F1..F19 键”并选中“Macbook Pro”或“Macbook Air”选项,选择正确的 mac 类型。