Created
May 9, 2017 01:19
-
-
Save m-mizutani/d120f79f6b25c831bb8e24fe2f664403 to your computer and use it in GitHub Desktop.
hammerspoon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" and name ~= "Google Chrome" then | |
if name ~= "iTerm2" then | |
enableAllHotkeys() | |
else | |
disableAllHotkeys() | |
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'}, 'a', keyCode('left', {'cmd'})) | |
remapKey({'ctrl'}, 'e', keyCode('right', {'cmd'})) | |
-- テキスト編集 | |
remapKey({'ctrl'}, 'w', keyCode('x', {'cmd'})) | |
remapKey({'ctrl'}, 'y', keyCode('v', {'cmd'})) | |
remapKey({"ctrl"}, "h", keyCode("delete")) | |
-- remapKey({"ctrl"}, "k", killLine()) | |
local function keyCtrlK() | |
keyCode('e', {'shift', 'ctrl'})() | |
keyCode('x', {'cmd'})() | |
end | |
hs.hotkey.bind({'ctrl'}, 'k', keyCtrlK, nil, keyCtrlK) | |
-- コマンド | |
remapKey({'ctrl'}, 's', keyCode('f', {'cmd'})) | |
remapKey({'ctrl'}, '/', keyCode('z', {'cmd'})) | |
remapKey({'ctrl'}, 'g', keyCode('escape')) | |
-- ページスクロール | |
remapKey({'ctrl'}, 'v', keyCode('pagedown')) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment