• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

[ScriptUI] ALT keydown listener on the Window object

Advocate ,
Sep 08, 2016 Sep 08, 2016

Copy link to clipboard

Copied

Hi,

I've a half baked demo dialog:

var res = """dialog {

  orientation: 'column',

  okButton: Button { text: 'OK' },

  cancelButton: Button { text: 'Cancel' },

         resetButton: Button { text: 'Reset the Cancel button'}

  }""";

var win = new Window(res);

win.resetButton.addEventListener('click', function(evt){

    win.cancelButton.text = 'Cancel';

})

win.addEventListener('keydown', function(evt) {

     if(true /* SUBSTITUTE HERE WORKING CONDITIONAL */) {

         win.cancelButton.text = "Reset";

    }

});

win.show()

Which looks like that:

DB 2016-09-08 at 11.17.55.png

I'd like to listen, in the main Window, to the ALT keydown, so that the Cancel button text turns into "Reset", as it is with Adobe's dialogs.

Problems:

  1. the keypress is forbidden in PS (beeps – while it is actually listened in ESTK)
  2. I can't find the right conditional to stick in the if)

Apparently ALT, as well as other modifier keys, works (at least in ESTK) only in conjunction with other keys, e.g. I can detect ALT+something (say ALT+A), but not ALT alone.

So, are these two problems unavoidable? Is it possible to listen to keydown in Dialog Windows in Photoshop? Can I listen to a modifier key only? I can probably listen for the modifier key in the button's click handler, but I'd like to have a visual feedback as well.

Thank you in advance!

Davide

TOPICS
Actions and scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Enthusiast ,
Sep 08, 2016 Sep 08, 2016

Copy link to clipboard

Copied

Hi Davide!

It only works when the Window is under mouse focus.

Try this:

var res = """dialog { 

  orientation: 'column', 

  okButton: Button { text: 'OK' }, 

  cancelButton: Button { text: 'Cancel' }, 

         resetButton: Button { text: 'Reset the Cancel button'} 

  }"""; 

var win = new Window(res);

var mouseEventHandler = function(ev) {

    if (ScriptUI.environment.keyboardState.altKey) {

        win.resetButton.text = ev.type + ' || Reset'; // you can see the event type changing on the reset button text

    }

};

// Register the mouse event handler

win.addEventListener('mouseover', mouseEventHandler);

win.addEventListener('mouseout', mouseEventHandler);

win.addEventListener('mousemove', mouseEventHandler);

// these 2 are not so important: it only works 1 time and then always be mousemove when scrooling:

win.addEventListener('mousedown', mouseEventHandler);

win.addEventListener('mouseup', mouseEventHandler);

// there is no other option when loosing the Window focus

win.show()

Sorry, but it is an half-help...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Sep 08, 2016 Sep 08, 2016

Copy link to clipboard

Copied

Hi Pedro,

that's very close, thanks! At least on CC2015.5 there is a drawback, see this one:

That is, the Listener doesn't seem to be attached to, or affect the, whole Window, but the Button only – i.e. if ALT is pressed when the mouse pointer is not on the Button, nothing happens (while it should)

Moreover, if you ALT then mouseOver (Cancel -> Reset), then while ALT is pressed you mouseOut, then release ALT, the text remains Reset (should become Cancel).

We all love ScriptUI 😉

The code I've used:

var res = """dialog {   

  orientation: 'column',   

  okButton: Button { text: 'OK' },   

  cancelButton: Button { text: 'Cancel' },   

  }""";   

 

var win = new Window(res);  

var mouseEventHandler = function(ev) { 

    if (ScriptUI.environment.keyboardState.altKey) { 

        win.cancelButton.text = 'Reset'; // you can see the event type changing on the reset button text 

    }  else { win.cancelButton.text = 'Cancel' }

}; 

 

// Register the mouse event handler 

win.addEventListener('mouseover', mouseEventHandler); 

win.addEventListener('mouseout', mouseEventHandler); 

win.addEventListener('mousemove', mouseEventHandler); 

// these 2 are not so important: it only works 1 time and then always be mousemove when scrooling: 

win.addEventListener('mousedown', mouseEventHandler);  

win.addEventListener('mouseup', mouseEventHandler); 

// there is no other option when loosing the Window focus 

 

win.show()

Thanks again,

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 08, 2016 Sep 08, 2016

Copy link to clipboard

Copied

LATEST

And this, may be anothe little step over. If the ivent is mouseout, the text will be always Cancel:

var res = """dialog {     

  orientation: 'column',     

  okButton: Button { text: 'OK' },     

  cancelButton: Button { text: 'Cancel' },     

  }""";     

   

var win = new Window(res);    

var mouseEventHandler = function(ev) {

    if (ev.type == 'mouseout') {

        win.cancelButton.text = 'Cancel';

    } else {

        if (ScriptUI.environment.keyboardState.altKey) {   

            win.cancelButton.text = 'Reset'; // you can see the event type changing on the reset button text   

        } else { win.cancelButton.text = 'Cancel' } 

    }

};   

   

// Register the mouse event handler   

win.addEventListener('mouseover', mouseEventHandler);   

win.addEventListener('mouseout', mouseEventHandler);   

win.addEventListener('mousemove', mouseEventHandler);   

// these 2 are not so important: it only works 1 time and then always be mousemove when scrooling:   

win.addEventListener('mousedown', mouseEventHandler);    

win.addEventListener('mouseup', mouseEventHandler);   

win.show() 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines