Skip to content

Instantly share code, notes, and snippets.

@griffin-stewie
Created December 23, 2016 02:28
Show Gist options
  • Save griffin-stewie/ebb1f24194af6b0ccc86f93900103244 to your computer and use it in GitHub Desktop.
Save griffin-stewie/ebb1f24194af6b0ccc86f93900103244 to your computer and use it in GitHub Desktop.
-- based on https://github.com/naoya/hammerspoon-init
local function keyCode(key, modifiers)
modifiers = modifiers or {}
return function()
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), true):post()
hs.timer.usleep(1000)
hs.eventtap.event.newKeyEvent(modifiers, string.lower(key), false):post()
end
end
local function keyCodeSet(keys)
return function()
for i, keyEvent in ipairs(keys) do
keyEvent()
end
end
end
local function remapKey(modifiers, key, keyCode)
hs.hotkey.bind(modifiers, key, keyCode, nil, keyCode)
end
local function disableAllHotkeys()
for k, v in pairs(hs.hotkey.getHotkeys()) do
v['_hk']:disable()
end
end
local function enableAllHotkeys()
for k, v in pairs(hs.hotkey.getHotkeys()) do
v['_hk']:enable()
end
end
local function handleGlobalAppEvent(name, event, app)
if event == hs.application.watcher.activated then
-- hs.alert.show(name)
id = app:bundleID()
if id == "com.apple.Terminal" then
disableAllHotkeys()
else
enableAllHotkeys()
end
end
end
appsWatcher = hs.application.watcher.new(handleGlobalAppEvent)
appsWatcher:start()
-- カーソル移動
remapKey({'ctrl'}, 'f', keyCode('right'))
remapKey({'ctrl'}, 'b', keyCode('left'))
remapKey({'ctrl'}, 'n', keyCode('down'))
remapKey({'ctrl'}, 'p', keyCode('up'))
remapKey({'ctrl'}, 'e', keyCode('right', {'cmd'}))
remapKey({'ctrl'}, 'a', keyCode('left', {'cmd'}))
-- テキスト編集
remapKey({'ctrl'}, 'd', keyCode('forwarddelete'))
remapKey({'ctrl'}, 'h', keyCode('delete'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment