Copy link to clipboard
Copied
Hello!
I am attempting to write a script that opens a dialog window. How would I be able to have the window open at the current mouse position?
var cursor = (getXY());
var w = new Window("dialog", 'Test');
w.preferredSize = [200, 200];
w.location = [cursor[0], cursor[1]]
w.show();
function getXY() {
var w = new Window("dialog {alignChildren: ['fill','fill'], margins: 0, opacity : 0.01}"),
g = w.add("button"),
X, Y;
w.preferredSize = [$.screens[0].right, $.screens[0].bottom]
g.addEventListener('mouseover', handler)
function handler(evt) { w.close(); X = evt.screenX, Y = evt.screenY }
w.show();
r
...
Copy link to clipboard
Copied
var cursor = (getXY());
var w = new Window("dialog", 'Test');
w.preferredSize = [200, 200];
w.location = [cursor[0], cursor[1]]
w.show();
function getXY() {
var w = new Window("dialog {alignChildren: ['fill','fill'], margins: 0, opacity : 0.01}"),
g = w.add("button"),
X, Y;
w.preferredSize = [$.screens[0].right, $.screens[0].bottom]
g.addEventListener('mouseover', handler)
function handler(evt) { w.close(); X = evt.screenX, Y = evt.screenY }
w.show();
return [X, Y]
}
Copy link to clipboard
Copied
Thank you! If I understand correctly, this is a function that creates a fullscreen button with a mouseover event listener that closes and returns the X Y values?
Copy link to clipboard
Copied
Yes that's right.
Unfortunately, ScritpUI does not allow us to get the mouse coordinates directly, so we have to resort to such tricks.
Copy link to clipboard
Copied
Makes sense. I added
w.opacity = 0;
to the function to make it a little less jarring as well.
Copy link to clipboard
Copied
It's strange that this works.
For me, when w.opacity = 0, the eventListener stops firing (that is, the window elements do not catch the event). That is, i need to set any value of transparency, except zero.