My issue is as follows: I have my caps lock remapped to F18 using Karabiner Elements, and then Hammerspoon uses F18 as a "hyper key" to perform app specific shortcuts.
My current code looks like this:
-- A global variable for the Hyper Mode
k = hs.hotkey.modal.new({}, "F17")
launch = function(bundleID)
hs.application.launchOrFocusByBundleID(bundleID)
k.triggered = true
end
-- Single keybinding for app launch
singleapps = {
{'f', 'com.apple.Finder'},
{'c', 'com.google.Chrome'},
}
for i, app in ipairs(singleapps) do
k:bind({}, app[1], function() launch(app[2]); end, nil, function() launch(app[2]); end)
I also have HJKJ mapped to arrow keys when using the hyper key to have vim like navigation everywhere:
arrowKey = function(arrow, modifiers)
local event = require("hs.eventtap").event
event.newKeyEvent(modifiers, string.lower(arrow), true):post()
event.newKeyEvent(modifiers, string.lower(arrow), false):post()
end
k:bind({}, 'h', function() arrowKey('LEFT', {}); end, nil, function() arrowKey('LEFT', {}); end)
k:bind({}, 'j', function() arrowKey('DOWN', {}); end, nil, function() arrowKey('DOWN', {}); end)
k:bind({}, 'k', function() arrowKey('UP', {}); end, nil, function() arrowKey('UP', {}); end)
k:bind({}, 'l', function() arrowKey('RIGHT', {}); end, nil, function() arrowKey('RIGHT', {}); end)
So HYPER-H
outputs the left arrow key basically. But my issue is that I also want HYPER-COMMAND-H
to output command-left-arrow-key as that brings the cursor to the beginning of the line.
k:bind({'cmd'}, 'n', function() arrowKey('LEFT', {'cmd'}); end, nil, function() arrowKey('LEFT', {'cmd'}); end)
I have it looking like that. However, the issue is that HYPER-COMMAND-H works, but COMMAND-HYPER-H does not. If I mess up the order of the modifiers (which normally does not matter) it completely breaks, which is super inconvenient.
How would I make it so that the order doesn't matter? F18 isn't a proper modifier key so I'm having real trouble.