Created
May 23, 2017 16:35
-
-
Save usagimaru/642c247d3e207bb5d6cc6c8af4037ecc to your computer and use it in GitHub Desktop.
hammerspoon key config
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 KEY_EISU = 0x66 | |
local KEY_KANA = 0x68 | |
local KEY_LCMD = 55 | |
local KEY_RCMD = 54 | |
local KEY_LOPT = 58 | |
local KEY_ROPT = 61 | |
local KEY_ESC = 53 | |
local KEY_CTRL = 59 | |
local KEY_RETURN = 52 | |
local KEY_BSLASH = 42 | |
local KEY_FDEL = 0x75 | |
local KEY_BDEL = 0x33 | |
local function keyCode(key, mods, callback) | |
mods = mods or {} | |
callback = callback or function() end | |
return function() | |
hs.eventtap.event.newKeyEvent(mods, string.lower(key), true):post() | |
hs.timer.usleep(1000) | |
hs.eventtap.event.newKeyEvent(mods, string.lower(key), false):post() | |
callback() | |
end | |
end | |
local function remapKey(mods, key, keyCode) | |
hs.hotkey.bind(mods, key, keyCode, nil, keyCode) | |
end | |
local function switchHotKeys(enable) | |
for k, v in pairs(hs.hotkey.getHotkeys()) do | |
if enable then | |
v["_hk"]:enable() | |
else | |
v["_hk"]:disable() | |
end | |
end | |
end | |
local function handleGlobalEvent(name, event, app) | |
if event == hs.application.watcher.activated then | |
if name == "Emacs" then | |
switchHotKeys(false) | |
else | |
switchHotKeys(true) | |
end | |
end | |
end | |
watcher = hs.application.watcher.new(handleGlobalEvent) | |
watcher:start() | |
remapKey({"ctrl"}, "p", keyCode("up")) | |
remapKey({"ctrl"}, "n", keyCode("down")) | |
remapKey({"ctrl"}, "f", keyCode("right")) | |
remapKey({"ctrl"}, "b", keyCode("left")) | |
remapKey({"ctrl"}, "a", keyCode("left", {"cmd"})) | |
remapKey({"ctrl"}, "e", keyCode("right", {"cmd"})) | |
-- remapKey({"ctrl"}, "h", keyCode("delete")) | |
-- remapKey({"ctrl"}, "d", keyCode("forwarddelete")) | |
remapKey({"ctrl"}, "return", keyCode("escape")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment