Feature request: hs.hotkey.bind - Allow to use fn/globe/🌐 key as a modifier
Title
Yes please!
When I run
hs.hotkey.bind(
{"cmd","alt","shift","ctrl","fn"},
"e",
function()
print(hs.inspect(hs.eventtap.checkKeyboardModifiers()))
end
)
in the HS console, I get
yyyy-mm-dd hh:mm:ss: hotkey: Enabled hotkey ✧E
Then, when I press Cmd Alt Shift Ctrl e, I get
yyyy-mm-dd hh:mm:ss: {
alt = true,
cmd = true,
ctrl = true,
shift = true,
["⇧"] = true,
["⌃"] = true,
["⌘"] = true,
["⌥"] = true
}
but Cmd Alt Shift Ctrl Fn e does nothing.
The fn is ignored entirely by hs.hotkey.bind() and not present in the output of hs.inspect(hs.eventtap.checkKeyboardModifiers())).
I could use Hyper (Cmd Alt Shift Ctrl), but I prefer to use Fn, because then HS could function independently of Karabiner and my HS shortcuts could fit in with native macOS window management shortcuts: https://support.apple.com/guide/mac-help/mac-window-tiling-icons-keyboard-shortcuts-mchl9674d0b0/mac
When I run
hs.hotkey.bind( {"cmd","alt","shift","ctrl","fn"}, "e", function() print(hs.inspect(hs.eventtap.checkKeyboardModifiers())) end )
Run this code:
-- Create a local variable to store the eventtap watcher so it isn't garbage collected
local modifierWatcher = hs.eventtap.new({hs.eventtap.event.types.flagsChanged}, function(event)
-- Get the current state of all modifiers (cmd, alt, shift, ctrl, fn, capslock)
local modifiers = hs.eventtap.checkKeyboardModifiers()
-- Format the active modifiers into a readable string
local activeMods = {}
for mod, isPressed in pairs(modifiers) do
if isPressed then
table.insert(activeMods, mod)
end
end
print("Pressed Modifiers: " .. table.concat(activeMods, ", "))
end)
modifierWatcher:start()
and you will see that Hamerspoon correctly report: "Pressed Modifiers: fn" when you press fn or Globe key.
But my prolem is that this code:
hs.hotkey.bind({"fn"}, "b", function()
hs.alert.show("You pressed fn + B!")
end)
does not get invoke if you press fn + b but it get invoke if you press only b! 😔
So, Hammerspoon detect fn press in hs.eventtap.checkKeyboardModifiers() but for some reason it wont detect in it .bind!
What is more intreguing, I can not assign in System Settings > Keyboard Shortcuts any shortcuts with fn (globe) key although I can see that there are many default "globe" shortcuts defined! More at: https://forums.macrumors.com/threads/function-key-globe-key-as-shortcut.2470194/
btw why my code is not properly repsrent in this post?!? `` <- this should render text as monotype font?
btw2 it is not single as you get when you press on icon but triple ``` ... gosh.