Created
July 26, 2020 15:44
-
-
Save janily/a0106f1a0b25c41821500e95fa75c4d4 to your computer and use it in GitHub Desktop.
mouse location
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
function mouseInCanvasViewForDocument(document) { | |
var mouseInWindow = document.documentWindow().convertScreenToBase(NSEvent.mouseLocation()); | |
return document.contentDrawView().convertPoint_fromView(mouseInWindow,null); | |
} | |
function CGPointToObject(point) { | |
return { | |
x: point.x.doubleValue(), | |
y: point.y.doubleValue() | |
} | |
} | |
// Alternative approach with the same result | |
/* | |
function CGPointToObject(point) { | |
return { | |
x: point.x + 0, | |
y: point.y + 0 | |
} | |
} | |
*/ | |
var point = CGPointToObject(mouseInCanvasViewForDocument(context.document)); | |
print(point); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment