在macOS的中文输入法中使用英文标点符号
在macOS的中文输入法中使用英文标点符号
作为一个程序狗, 输入的标点符号主要都是英文标点符号, 在Windows下可以很方便得开启 使用英文标点符号 选项
但是在macOS里, 即使开启了 使用半角 选项, 像大括号这样还都是中文, 十分不方便
这里我打算使用 HammerSpoon 来解决这个问题
安装 hammerspoon
BASH
brew install hammerspoon配置 hammerspoon
在安装完成后, 它会在 ~/.hammerspoon 目录下生成一个 init.lua 文件, 我们在这个文件中进行配置
init.lua
init.lua
require("chinese")
hs.notify.new({title="Hammerspoon", informativeText="成功加载配置"}):send()chinese.lua
chinese.lua
function SendKey(key)
hs.eventtap.keyStrokes(key)
end
hs.hotkey.bind("", "`", hs.fnutils.partial(SendKey, "`"))
hs.hotkey.bind("", "'", hs.fnutils.partial(SendKey, "'"))
hs.hotkey.bind("", "\\", hs.fnutils.partial(SendKey, "\\"))
hs.hotkey.bind("shift", "4", hs.fnutils.partial(SendKey, "$"))
hs.hotkey.bind("shift", "6", hs.fnutils.partial(SendKey, "^"))
hs.hotkey.bind("shift", "-", hs.fnutils.partial(SendKey, '_'))
hs.hotkey.bind("shift", "[", hs.fnutils.partial(SendKey, "{"))
hs.hotkey.bind("shift", "]", hs.fnutils.partial(SendKey, "}"))
hs.hotkey.bind("shift", "'", hs.fnutils.partial(SendKey, '"'))
hs.hotkey.bind("shift", ",", hs.fnutils.partial(SendKey, '<'))
hs.hotkey.bind("shift", ".", hs.fnutils.partial(SendKey, '>'))这样可以将主要的中文标点符号直接替换为英文标点符号, 正常输入即可
甚至可以在 SendKey 中添加一些逻辑, 例如检测到当前为IDE的时候才发送英文符号, 在其他地方发送中文符号
LUA
function IsCodeWindows()
local codeWindows = { "CLion", "Code", "PyCharm", "Sublime Text", "WebStorm", "IntelliJ IDEA", "GLand" }
local win = hs.window.focusedWindow()
local app = win:application()
local appName = app:name()
for _, v in ipairs(codeWindows) do
if v == appName then
return true
end
end
return false
end在macOS的中文输入法中使用英文标点符号
https://simonkimi.githubio.io/posts/20260320125605/