You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to Hammerspoon, and I absolutely love it. But I'm having a hard time getting precisely the results that I want, and many of my attempts bork my system so bad I have to pull the Macbook off the dock, reboot with hardware power key, and then be careful not to execute the borked combo upon login before reediting the config file to unbork it.
Primarily there are only two things I want to accomplish, pretty simple:
while holding right mouse button, use mousewheel to control system volume
while holding right mouse button, press another mouse button (4 to choose from) to execute some canned action
Here's what I have so far:
local eventtap = require("hs.eventtap")
volume_control = eventtap.new({eventtap.event.types.scrollWheel}, function(event)
if eventtap.checkMouseButtons()[2] then
hs.eventtap.keyStroke({}, "escape", 0); -- Make the context menu disappear
local vol = hs.audiodevice.defaultOutputDevice():volume()
if (event:getProperty(hs.eventtap.event.properties.scrollWheelEventDeltaAxis1) < 0) then vol = vol + 2 end
if (event:getProperty(hs.eventtap.event.properties.scrollWheelEventDeltaAxis1) > 0) then vol = vol - 2 end
hs.audiodevice.defaultOutputDevice():setVolume(vol)
hs.alert.closeAll()
hs.alert.show(string.format("Volume: %3.0f%%", hs.audiodevice.defaultOutputDevice():volume()), {}, hs.screen.mainScreen(), 0.4)
return true
end
end):start()
mission_control = eventtap.new({eventtap.event.types.leftMouseDown}, function(event)
if eventtap.checkMouseButtons()[2] then
hs.eventtap.keyStroke({}, "escape", 0); -- Make the context menu disappear
hs.spaces.openMissionControl()
return true
end
end):start()
Both bindings work, with one minor shortcoming. Whatever normally happens with a right click (e.g. usually a context menu of some sort) still happens when I start holding that button. This is a problem because (1) I don't want to see the menu and (2) I don't want to accidentally click anything in it.
#1 would be easier to solve if MacOS fired off the context menu on buttonUp like Windows does, but it gets fired off on buttonDown, unfortunately. That part makes me not sure if it's even possible to accomplish my goal... but if it is possible, my lack of expertise here is not helping. To be clear, I still want the context menu to pop up if I don't touch the mouse wheel or other mouse buttons while holding the right mouse button... and obviously the only logical way to accomplish this is to open the context menu on buttonUp like Windows does (and also keep track of what does or doesn't happen while the button is down, which I don't know how to do). Basically I think I need to (a) remap the normal right-click action to happen on buttonUp, but (b) cancel that event if one of my other special things happened before buttonUp.
For #2, I think I'm safe, even without my "send escape key" hack which is kind of an unneeded failsafe. E.g. if in a web browser I first hold right mouse, then click "reload" in the context menu that pops up... Mission Control opens up (good) and the reload is NOT executed (also good). So I guess that leaves #1 as my only issue, which is admittedly minor (just a visual annoyance since I briefly see a menu I don't need).
I've tried approaching this from very different angles where I don't propagate the events based on certain conditions, but those are the attempts that will bork my system and make it stop responding to all keyboard and mouse button inputs. Does anybody else have any ideas? Thanks!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm new to Hammerspoon, and I absolutely love it. But I'm having a hard time getting precisely the results that I want, and many of my attempts bork my system so bad I have to pull the Macbook off the dock, reboot with hardware power key, and then be careful not to execute the borked combo upon login before reediting the config file to unbork it.
Primarily there are only two things I want to accomplish, pretty simple:
Here's what I have so far:
Both bindings work, with one minor shortcoming. Whatever normally happens with a right click (e.g. usually a context menu of some sort) still happens when I start holding that button. This is a problem because (1) I don't want to see the menu and (2) I don't want to accidentally click anything in it.
#1 would be easier to solve if MacOS fired off the context menu on buttonUp like Windows does, but it gets fired off on buttonDown, unfortunately. That part makes me not sure if it's even possible to accomplish my goal... but if it is possible, my lack of expertise here is not helping. To be clear, I still want the context menu to pop up if I don't touch the mouse wheel or other mouse buttons while holding the right mouse button... and obviously the only logical way to accomplish this is to open the context menu on buttonUp like Windows does (and also keep track of what does or doesn't happen while the button is down, which I don't know how to do). Basically I think I need to (a) remap the normal right-click action to happen on buttonUp, but (b) cancel that event if one of my other special things happened before buttonUp.
For #2, I think I'm safe, even without my "send escape key" hack which is kind of an unneeded failsafe. E.g. if in a web browser I first hold right mouse, then click "reload" in the context menu that pops up... Mission Control opens up (good) and the reload is NOT executed (also good). So I guess that leaves #1 as my only issue, which is admittedly minor (just a visual annoyance since I briefly see a menu I don't need).
I've tried approaching this from very different angles where I don't propagate the events based on certain conditions, but those are the attempts that will bork my system and make it stop responding to all keyboard and mouse button inputs. Does anybody else have any ideas? Thanks!
Beta Was this translation helpful? Give feedback.
All reactions