init.lua
-- Shift + Spaceでローマ字入力とひらがな入力を切り替え
hs.hotkey.bind({"shift"}, "space",
function()
local currentMethod = hs.keycodes.currentMethod()
--hs.alert.show(currentMethod)
if currentMethod == "Romaji" then
hs.keycodes.setMethod("Hiragana")
ime = "Hiragana"
else
hs.keycodes.setMethod("Romaji")
ime = "Romaji"
end
end
)
-- TerminalとMacVimの時にcmdをctrlにする
modmod = false
local function handleGlobalEvent(name, event, app)
--hs.alert.show(name)
if event == hs.application.watcher.activated then
if name == "MacVim" or name == "ターミナル" or name == "XQuartz" then
modmod = true
else
modmod = false
end
end
end
watcher = hs.application.watcher.new(handleGlobalEvent)
watcher:start()
keyboardTracker = hs.eventtap.new({hs.eventtap.event.types.keyDown}, function (e)
local flags = e:getFlags()
local keyCode = e:getKeyCode()
--hs.alert.show(flags)
--hs.alert.show(keyCode)
if modmod and flags.cmd then
hs.eventtap.event.newKeyEvent(hs.keycodes.map.ctrl,true):post()
hs.eventtap.event.newKeyEvent(keyCode,true):post()
return true
end
end)
keyboardTracker:start()