Skip to content

Instantly share code, notes, and snippets.

@mfks17
Created January 5, 2018 22:16
Show Gist options
  • Save mfks17/2c88d353d2661e10128d5b1c5e0fa374 to your computer and use it in GitHub Desktop.
Save mfks17/2c88d353d2661e10128d5b1c5e0fa374 to your computer and use it in GitHub Desktop.
My Hammerspoon init script 🔨
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 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)
if name ~= "iTerm2" then
enableAllHotkeys()
else
disableAllHotkeys()
end
end
end
-- カーソル移動
remapKey({'ctrl'}, 'f', keyCode('right'))
remapKey({'ctrl'}, 'b', keyCode('left'))
remapKey({'ctrl'}, 'n', keyCode('down'))
remapKey({'ctrl'}, 'p', keyCode('up'))
-- コマンド
remapKey({'ctrl'}, 's', keyCode('f', {'cmd'}))
remapKey({'ctrl'}, 'g', keyCode('escape'))
remapKey({'ctrl'}, 'm', keyCode('return'))
-- ページスクロール
remapKey({'ctrl'}, 'v', keyCode('pagedown'))
remapKey({'alt'}, 'v', keyCode('pageup'))
remapKey({'cmd', 'shift'}, ',', keyCode('home'))
remapKey({'cmd', 'shift'}, '.', keyCode('end'))
-- https://qiita.com/naoya@github/items/81027083aeb70b309c14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment