Created
November 2, 2022 07:45
-
-
Save kiinoda/71d8227ce148adc017eeb52c5360520c to your computer and use it in GitHub Desktop.
Hammerspoon - undo/redo on mouse left/right on keypress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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