#author("2023-02-05T23:43:55+09:00","default:ichinomoto","ichinomoto") #author("2023-02-12T01:04:18+09:00","default:ichinomoto","ichinomoto") [[mac]] init.lua -- Shift + Spaceでローマ字入力とひらがな入力を切り替え hs.hotkey.bind({"shift"}, "space", function() local currentMethod = hs.keycodes.currentMethod() --hs.alert.show(currentMethod) 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 if currentMethod == "Romaji" then hs.keycodes.setMethod("Hiragana") else hs.keycodes.setMethod("Romaji") end end ) -- TerminalとMacVimの時にcmdをctrlにする modmod = false -- 特定アプリ以外ではcaps(ctrlに設定)をcmdにする capsTo = "ctrl" 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 capsTo = "ctrl" else modmod = false capsTo = "cmd" 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 keyboardTracker = hs.eventtap.new({hs.eventtap.event.types.keyDown, hs.eventtap.event.types.leftMouseDown}, function (e) --keyboardTracker = hs.eventtap.new({hs.eventtap.event.types.keyDown}, function (e) local flags = e:getFlags() -- print(flags.ctrl) if (capsTo == "cmd" and flags.ctrl) then -- print("set cmd") local eventType = e:getType(true) if (eventType == hs.eventtap.event.types.keyDown) then local keyCode = e:getKeyCode() -- print(keyCode) -- print("cmd + key") hs.eventtap.event.newKeyEvent(hs.keycodes.map.cmd,true):post() hs.eventtap.event.newKeyEvent(keyCode,true):post() hs.eventtap.event.newKeyEvent(keyCode,false):post() hs.eventtap.event.newKeyEvent(hs.keycodes.map.cmd,false):post() return true elseif (eventType == hs.eventtap.event.types.leftMouseDown) then local pointerPos = hs.mouse.absolutePosition() -- print("cmd + leftMouse") hs.eventtap.event.newMouseEvent(hs.eventtap.event.types.leftMouseDown, {x=pointerPos.x, y=pointerPos.y}, {"cmd"}):post() hs.eventtap.event.newMouseEvent(hs.eventtap.event.types.leftMouseUp, {x=pointerPos.x, y=pointerPos.y}, {"cmd"}):post() return true end end end) keyboardTracker:start()