Created
July 25, 2020 04:45
-
-
Save kyounger/c0d9ee86aec0e16a9f05cbe33c8f50ae to your computer and use it in GitHub Desktop.
hammerspoon draw box and obtain coordinates
This file contains hidden or 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(modShiftHyper, "W", function() | |
-- local tracking = false | |
local startingMousePosition = hs.mouse.getAbsolutePosition() | |
local max = hs.screen.mainScreen():fullFrame() | |
local maxCanvas = hs.canvas.new{x=max.x, y=max.y, h=max.h, w=max.w} | |
maxCanvas:clickActivating(false) | |
maxCanvas:canvasMouseEvents(true, true, false, true) | |
maxCanvas:mouseCallback(function(_, event, id, x, y) | |
local currentMousePosition = hs.mouse.getAbsolutePosition() | |
if event == "mouseMove" then | |
-- if tracking then | |
maxCanvas:replaceElements({ | |
type="rectangle", | |
action="stroke", | |
strokeWidth=2.0, | |
strokeColor= {green=1.0}, | |
frame = { | |
x=startingMousePosition.x, | |
y=startingMousePosition.y, | |
h=(currentMousePosition.y-startingMousePosition.y), | |
w=(currentMousePosition.x-startingMousePosition.x) | |
}, | |
}) | |
-- end | |
-- elseif event == "mouseDown" then | |
-- tracking=true | |
elseif event == "mouseUp" then | |
print(hs.inspect(startingMousePosition)) | |
print(hs.inspect(currentMousePosition)) | |
maxCanvas:delete() | |
end | |
end) | |
maxCanvas:level("dragging") | |
maxCanvas:show() | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this! I learned some things from it.