在运行 Sonoma 的新款 M3 MacBook Air 上,如何将听写(麦克风符号)和焦点(月亮符号)功能键更改为使 Discord 静音和消音?
我根本不使用这些键。键盘设置中唯一简单的选项是关闭全部功能键,这不是我想要的。
答案1
为此,您需要使用新的 hidutil 功能(我相信它仅适用于 Apple Silicon 型号,但我尚未确认)以及 Hammerspoon。
第一步是添加一个 plist 文件,使用苹果新的 hidutil 函数将这两个键“翻转”为它们的默认值f5和f6功能,而不是 macOS 用途。创建一个名为的文件~/Library/LaunchAgents/com.local.KeyRemapping.plist
,并用以下内容填充它:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.local.KeyRemapping</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/hidutil</string>
<string>property</string>
<string>--set</string>
<string>{"UserKeyMapping":[
{
"HIDKeyboardModifierMappingSrc": 0xC000000CF,
"HIDKeyboardModifierMappingDst": 0x70000003E
},
{
"HIDKeyboardModifierMappingSrc": 0x10000009B,
"HIDKeyboardModifierMappingDst": 0x70000003F
}
]}</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
第二步是使用 Hammerspoon 将f5和翻译f6成 discord 的静音和静音热键,command shift m and d
分别是。将此代码放入您的~/.hammerspoon/init.lua
:
-- this function checks if discord is open, and if it is it sends it (while in the background or in focus) the cmd+shift+m mute hotkeys
function mutediscord()
local discordapp = hs.application.find("Discord")
-- print(discordapp)
if discordapp ~= nil then
-- print("Discord is open")
hs.eventtap.event.newKeyEvent(hs.keycodes.map.m, true):rawFlags(hs.eventtap.event.rawFlagMasks['command'] | hs.eventtap.event.rawFlagMasks['shift']):post(discordapp)
hs.eventtap.event.newKeyEvent(hs.keycodes.map.m, false):rawFlags(hs.eventtap.event.rawFlagMasks['command'] | hs.eventtap.event.rawFlagMasks['shift']):post(discordapp)
-- else
-- print("discord is closed")
end
end
--I used hidutil to flip the f5 and f6 keys
hs.hotkey.bind({}, "f5", mutediscord)
-- this function checks if discord is open, and if it is it sends it (while in the background or in focus) the cmd+shift+d deafen hotkeys
function deafendiscord()
local discordapp = hs.application.find("Discord")
-- print(discordapp)
if discordapp ~= nil then
-- print("Discord is open")
hs.eventtap.event.newKeyEvent(hs.keycodes.map.d, true):rawFlags(hs.eventtap.event.rawFlagMasks['command'] | hs.eventtap.event.rawFlagMasks['shift']):post(discordapp)
hs.eventtap.event.newKeyEvent(hs.keycodes.map.d, false):rawFlags(hs.eventtap.event.rawFlagMasks['command'] | hs.eventtap.event.rawFlagMasks['shift']):post(discordapp)
-- else
-- print("discord is closed")
end
end
hs.hotkey.bind({}, "f6", deafendiscord)
很确定你需要重启才能让 hidutil 正常工作。但现在你可以使用键盘快捷键在后台静音和取消静音 discord。我想你可以轻松地扩展它们来为多个程序做某事。
遗憾的是,如果您的计算机被锁定,您将需要将其解锁才能将自己静音。
附言:只是想添加一些能帮助我弄清楚这一点的来源。