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

Makes sense. I added

w.opacity = 0;

to the function to make it a little less jarring as well.


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.