Last active
July 16, 2017 06:55
-
-
Save Nyoho/2049083db32ef864e901b70c4a9d4401 to your computer and use it in GitHub Desktop.
my ~/.hammerspoon/init.lua at 2017年5月25日(木)
This file contains hidden or 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 hasValue (tab, val) | |
for index, value in ipairs(tab) do | |
if value == val then | |
return true | |
end | |
end | |
return false | |
end | |
local excludedApps = { | |
"Terminal", "ターミナル", "Emacs", "iTerm2" | |
} | |
local function handleGlobalAppEvent(name, event, app) | |
if event == hs.application.watcher.activated then | |
-- hs.alert.show(name) | |
if hasValue(excludedApps, name) 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'}, 'w', keyCode('x', {'cmd'})) | |
-- remapKey({'ctrl'}, 'y', keyCode('v', {'cmd'})) | |
-- コマンド | |
-- remapKey({'ctrl'}, 's', keyCode('f', {'cmd'})) | |
-- remapKey({'ctrl'}, '/', keyCode('z', {'cmd'})) | |
remapKey({'ctrl'}, 'g', keyCode('escape')) | |
-- ページスクロール | |
remapKey({'ctrl'}, 'v', keyCode('pagedown')) | |
remapKey({'alt'}, 'v', keyCode('pageup')) | |
remapKey({'cmd', 'shift'}, ',', keyCode('home')) | |
remapKey({'cmd', 'shift'}, '.', keyCode('end')) | |
local KEY_EISU = 0x66; | |
local KEY_KANA = 0x68; | |
local KEY_SPACE = 0x31; | |
local KEY_LEFT_SHIFT = 0x38; | |
local KEY_LEFT_CTRL = 0x3b; | |
local KEY_LEFT_OPTION = 0x3d; | |
local KEY_LEFT_COMMAND = 0x37; | |
local hyperex = require('hyperex') | |
--local hx = hyperex.new('f12'):setInitialKey(KEY_EISU):setEmptyHitKey(KEY_KANA) | |
local hxLCmd = hyperex.new('cmd'):setEmptyHitKey(KEY_EISU) | |
local hxRCmd = hyperex.new('ctrl'):setEmptyHitKey(KEY_KANA) | |
-- hxRCmd:mod({'ctrl'}):to('any') | |
-- local rcmd = hyperex.new('f17'):setEmptyHitKey(KEY_EISU) | |
-- rcmd:mod({'cmd'}):to('any') | |
-- local lcmd = hyperex.new('f18'):setEmptyHitKey(KEY_KANA) | |
-- lcmd:mod({'ctrl'}):to('any') | |
-- local sands = hyperex.new('space'):setInitialKey(KEY_LEFT_SHIFT):setEmptyHitKey(KEY_SPACE) | |
-- local sands = hyperex.new('space'):setInitialKey(KEY_EISU):setEmptyHitKey(KEY_SPACE) | |
-- local sands = hyperex.new('space'):setEmptyHitKey(KEY_SPACE) | |
-- sands:bind('k'):to(';') | |
-- sands:mod({'shift'}):to('any') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment