Distinguish between left and right modifiers #3113
Replies: 2 comments 2 replies
-
| 
         I can see some benefit to adding at least the table of modifiers to hs.eventtap.event somehow. I generally try to discourage using hs.eventtap for hotkeys, simply because it's a lot of overhead vs hs.hotkey where the OS is doing the work for us in a more optimised way. However, for cases where hs.hotkey can't meet a user's needs, it's certainly great to have options in hs.eventtap! Perhaps a good first step would be to submit it to the official Spoons repo?  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         The  Using  What I would personally do is a combination: Create your hotkeys with  Use eventtap to detect flag changes only; this puts less strain on Hammerspoon because it isn't having to deal with every single character press. When the left (or right) modifier you care about is set, turn on the series of hotkeys that you want active with  When the left (or right) modifier you care about is released, turn off the hotkeys with  Something like this (minimally tested) to get started: local hotkey   = require("hs.hotkey")
local eventtap = require("hs.eventtap")
local keycodes = require("hs.keycodes")
local alert    = require("hs.alert")
-- set up your hotkeys in this table:
local myKeys = {
    hotkey.new({ "cmd" }, "1", function() alert("1 was pressed") end),
    hotkey.new({ "cmd" }, "2", function() alert("2 was pressed") end),
    -- etc
}
local myKeysActive = false
-- this determines whether or not to enable/disable the keys
et = eventtap.new(
    { eventtap.event.types.flagsChanged },
    function(e)
        local flags = e:rawFlags()
        if flags & eventtap.event.rawFlagMasks.deviceRightCommand > 0 then
            if not myKeysActive then
                for _, v in ipairs(myKeys) do
                    v:enable()
                end
                myKeysActive = true
            end
        else
            if myKeysActive then
                for _, v in ipairs(myKeys) do
                    v:disable()
                end
                myKeysActive = false
            end
        end
    end
):start() | 
  
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I wanted to use right modifiers for binding my hotkeys but I realised the existing
hotkeyextension doesn't support it.So, I used
eventtapextension to listen forkeyDownevents and came up with this:which can be used like so
I'm wondering if it'd be worthwhile to add to it the main repo? (I'd be more than happy to clean-up this code and do it!)
Beta Was this translation helpful? Give feedback.
All reactions