Created
November 27, 2016 23:11
-
-
Save kitak/ead61d03f44d854b657ebffa230dcacc to your computer and use it in GitHub Desktop.
hammerspoon 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 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 | |
remapKey({}, 'f13', keyCodeSet({ | |
keyCode(';', {'ctrl', 'shift'}), | |
keyCode('escape', {}) | |
})) | |
-- For debug | |
local function showKeyPress(tapEvent) | |
local charactor = hs.keycodes.map[tapEvent:getKeyCode()] | |
hs.alert.show(charactor, 1.5) | |
end | |
local keyTap = hs.eventtap.new( | |
{hs.eventtap.event.types.keyDown}, | |
showKeyPress | |
) | |
k = hs.hotkey.modal.new({"cmd", "shift", "ctrl"}, 'P') | |
function k:entered() | |
hs.alert.show("Enabling Keypress Show Mode", 1.5) | |
keyTap:start() | |
end | |
function k:exited() | |
hs.alert.show("Disabling Keypress Show Mode", 1.5) | |
end | |
k:bind({"cmd", "shift", "ctrl"}, 'P', function() | |
keyTap:stop() | |
k:exit() | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment