Skip to main content
w0llay
Participant
August 18, 2022
Answered

Opening window on mouse.

  • August 18, 2022
  • 1 reply
  • 632 views

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?

This topic has been closed for replies.
Correct answer jazz-y

 

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]
}

 

1 reply

jazz-yCorrect answer
Legend
August 18, 2022

 

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]
}

 

w0llay
w0llayAuthor
Participant
August 18, 2022

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?

Legend
August 18, 2022

Yes that's right.

Unfortunately, ScritpUI does not allow us to get the mouse coordinates directly, so we have to resort to such tricks.