Skip to content

Instantly share code, notes, and snippets.

@kiinoda
Created November 2, 2022 07:45
Show Gist options
  • Save kiinoda/71d8227ce148adc017eeb52c5360520c to your computer and use it in GitHub Desktop.
Save kiinoda/71d8227ce148adc017eeb52c5360520c to your computer and use it in GitHub Desktop.
Hammerspoon - undo/redo on mouse left/right on keypress
hs.hotkey.bind({"cmd", "ctrl", "alt", "shift"}, "f1",
-- next function is called on hotkey press
function()
startPoint = hs.mouse.absolutePosition()
end,
-- this is called on hotkey release
function() end,
-- this is called while the key remains pressed
function()
local point = hs.mouse.absolutePosition()
if (startPoint.x ~= point.x) then
if (startPoint.x > point.x) then
-- moving left / undo
hs.eventtap.keyStroke({"cmd"}, "z", true)
else
print("r")
-- moving right / redo
hs.eventtap.keyStroke({"cmd", "shift"}, "z", true)
end
startPoint = point
end
end
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment