您可以使用OSX上的键盘快捷键打开/关闭功能键吗?


Answers:


9

要进行以下工作,您需要在系统偏好设置»通用访问中启用辅助设备的访问权限


打开Automator,选择Service并选择该服务不接收任何输入(靠近顶部)。

双击库中“ 实用工具”类别中的“运行AppleScript ”。使用以下内容替换新创建的操作的默认代码段:

tell application "System Preferences"
    set current pane to pane id "com.apple.preference.keyboard"
    tell application "System Events"
        tell process "System Preferences"
            click checkbox "Use all F1, F2, etc. keys as standard function keys" of tab group 1 of window "Keyboard"
        end tell
    end tell
    quit
end tell

系统偏好设置将启动,但不会显示,并会在切换设置后立即退出。

Command-S保存,给它命名,例如Toggle Fn。结果:

在此输入图像描述


转到系统偏好设置»键盘»键盘快捷键»服务,为此服务指定键盘快捷键。


1
如果执行此命令时系统首选项已在运行,则它将退出。防止这种情况的代码会增加这个答案。
Daniel Beck

问题是标记为osx-snow-leopard,这个答案似乎需要。我不认为我可以在OS X 10.5中提供服务,从我面前的情况来看,与gigaom.com/apple
Philip Durbin

@Philip我不记得服务如何在10.5中工作,但Automator创建的服务只是保存到的Automator工作流程~/Library/Services。也许你可以手动复制这个?要配置“服务”菜单,请使用ServiceScrubber。
Daniel Beck

这适用于10.6但由于某种原因我的键盘快捷键在我不想要的时候保持失败或触发。所以我转而使用基于stackoverflow.com/questions/3446128
Philip Durbin

@Philip您可以随时启用AppleScript菜单并将代码存储为scpt文件~/Library/Scripts并从菜单栏调用。使用第三方FastScripts,您可以指定键盘快捷键。
丹尼尔贝克

4

我知道这篇文章很老但是无法在Mountinan Lion上运行。我发现了一个类似的片段,但删除了一些不必要的部分。

tell application "System Preferences"
    set current pane to pane "com.apple.preference.keyboard"
end tell

tell application "System Events"
    -- If we don't have UI Elements enabled, then nothing is really going to work.
    if UI elements enabled then
        tell application process "System Preferences"
            get properties

            click radio button "Keyboard" of tab group 1 of window "Keyboard"
            click checkbox "Use all F1, F2, etc. keys as standard function keys" of tab group 1 of window "Keyboard"
        end tell
        tell application "System Preferences" to quit
    else
        -- GUI scripting not enabled.  Display an alert
        tell application "System Preferences"
            activate
            set current pane to pane "com.apple.preference.universalaccess"
            display dialog "UI element scripting is not enabled. Please activate \"Enable access for assistive devices\""
        end tell
    end if
end tell

希望这可以帮助


0

你也可以使用KeyRemap4MacBook这样的private.xml

<?xml version="1.0"?>
<root>
  <item>
    <name>test</name>
    <identifier>test</identifier>
    <autogen>__KeyToKey__ KeyCode::F1, VK_COMMAND | ModifierFlag::NONE, KeyCode::VK_CONFIG_TOGGLE_fn</autogen>
    <autogen>__KeyToKey__ KeyCode::BRIGHTNESS_DOWN, VK_COMMAND | ModifierFlag::NONE, KeyCode::VK_CONFIG_TOGGLE_fn</autogen>
  </item>
  <item>
    <name>fn</name>
    <identifier vk_config="true">fn</identifier>
    <autogen>__KeyToKey__ KeyCode::BRIGHTNESS_DOWN, KeyCode::F1</autogen>
    <autogen>__KeyToKey__ KeyCode::BRIGHTNESS_UP, KeyCode::F2</autogen>
    <autogen>__KeyToKey__ KeyCode::EXPOSE_ALL, KeyCode::F3</autogen>
    <autogen>__KeyToKey__ KeyCode::LAUNCHPAD, KeyCode::F4</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::KEYBOARDLIGHT_LOW, KeyCode::F5</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::KEYBOARDLIGHT_HIGH, KeyCode::F6</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::MUSIC_PREV, KeyCode::F7</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::MUSIC_PLAY, KeyCode::F8</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::MUSIC_NEXT, KeyCode::F9</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::VOLUME_MUTE, KeyCode::F10</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::VOLUME_DOWN, KeyCode::F11</autogen>
    <autogen>__ConsumerToKey__ ConsumerKeyCode::VOLUME_UP, KeyCode::F12</autogen>
    <autogen>__KeyToKey__ KeyCode::F1, KeyCode::BRIGHTNESS_DOWN</autogen>
    <autogen>__KeyToKey__ KeyCode::F2, KeyCode::BRIGHTNESS_UP</autogen>
    <autogen>__KeyToKey__ KeyCode::F3, KeyCode::EXPOSE_ALL</autogen>
    <autogen>__KeyToKey__ KeyCode::F4, KeyCode::LAUNCHPAD</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F5, ConsumerKeyCode::KEYBOARDLIGHT_LOW</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F6, ConsumerKeyCode::KEYBOARDLIGHT_HIGH</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F7, ConsumerKeyCode::MUSIC_PREV</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F8, ConsumerKeyCode::MUSIC_PLAY</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F9, ConsumerKeyCode::MUSIC_NEXT</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F10, ConsumerKeyCode::VOLUME_MUTE</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F11, ConsumerKeyCode::VOLUME_DOWN</autogen>
    <autogen>__ConsumerToKey__ KeyCode::F12, ConsumerKeyCode::VOLUME_UP</autogen>
  </item>
</root>

请参阅源代码以获取关键代码值预定义设置

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.