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

How to press the apply button through the "enter" key on the keyboard?

Contributor ,
May 29, 2017 May 29, 2017

Hi everyone, how do I press the apply button through the "enter" key on the keyboard?

I know that for this to happen, the button will first have to be selected by a blue border. As shown in picture B of the figure below. Thank you.

Screenshot_1.jpg

var dlg = new Window ("dialog", "My dialog", [0,0,0,0]) 

dlg.size = [200,100] 

dlg.location = [600,260]  

var dlgborda = dlg.add('panel', [10,5,190,80], '');

var b1 = dlgborda.add("button", [0,0,0,0], "Cancela") 

       b1.location = [10, 12] 

       b1.size = [70, 25]

var b2 = dlgborda.add("button", [0,0,0,0], "Apply") 

b2.location = [90,12] 

b2.size = [70, 25]  

b1.onClick = function(){

dlg.close()

}

b2.onClick = function(){

dlg.close()

tp(); 

dlg.show() 

function tp(){ 

  alert("To apply") 

}

TOPICS
Actions and scripting
1.8K
Translate
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

correct answers 1 Correct answer

Engaged , May 29, 2017 May 29, 2017

Hi Ps-Design!

I have researched right here in the forum and found in this script a few lines of code that can help you.

Script UI Strange behavior on keybord events.

I have not got experience with programming, but I did a little modification in your script:

var dlg = new Window ("dialog", "My dialog", [0,0,0,0])   

dlg.size = [200,100]   

dlg.location = [600,260]    

var dlgborda = dlg.add('panel', [10,5,190,80], ''); 

var btn_cancelar = dlgborda.add("button", [0,0,0,0], "Cancela")   

       btn

...
Translate
Adobe
Community Expert ,
May 29, 2017 May 29, 2017

Ps-Design​,

eg you can use the property "active"

var b2 = dlgborda.add("button", [0,0,0,0], "Apply")   

b2.location = [90,12]   

b2.size = [70, 25]

b2.active = true;

Have fun

Translate
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
Contributor ,
May 29, 2017 May 29, 2017

pixxxel schubser

Right! The button was actually selected, the next step will be to add a keyboard shortcut to make the button work by pressing the enter key. How to proceed?

Translate
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
Community Expert ,
May 29, 2017 May 29, 2017

This will works when running with target ESTK but not with target PS or Illu, sorry

var b2 = dlgborda.add("button", [0,0,0,0], "Apply")   

b2.location = [90,12]   

b2.size = [70, 25]

//b2.active = true;

b2.shortcutKey  = "1"; // use [Alt]+[1]

b2.onShortcutKey = b2.onClick;

Translate
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
Contributor ,
May 29, 2017 May 29, 2017

pixxxelschubser escreveu

 

This will works when running with target ESTK but not with target PS or Illu, sorry

var b2 = dlgborda.add("button", [0,0,0,0], "Apply")     b2.location = [90,12]     b2.size = [70, 25] //b2.active = true; b2.shortcutKey  = "1"; // use [Alt]+[1] b2.onShortcutKey = b2.onClick; 
 

Hi .... I tested here in Photoshop and it did not work, but I'm glad for your attention and willingness to help me! Thank you.

Translate
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
Engaged ,
May 29, 2017 May 29, 2017

Hi Ps-Design!

I have researched right here in the forum and found in this script a few lines of code that can help you.

Script UI Strange behavior on keybord events.

I have not got experience with programming, but I did a little modification in your script:

var dlg = new Window ("dialog", "My dialog", [0,0,0,0])   

dlg.size = [200,100]   

dlg.location = [600,260]    

var dlgborda = dlg.add('panel', [10,5,190,80], ''); 

var btn_cancelar = dlgborda.add("button", [0,0,0,0], "Cancela")   

       btn_cancelar.location = [10, 12]   

       btn_cancelar.size = [70, 25] 

var btn_enter = dlgborda.add("button", [0,0,0,0], "Apply")   

       btn_enter.location = [90,12]   

       btn_enter.size = [70, 25]

       btn_enter.active = true;

 

 

//Cancelar

btn_cancelar.onClick = function(){  

dlg.close() 

 

//Apply

function press_enter() {

dlg.close ()

comando();

}

 

 

dlg.addEventListener('keydown', function(event) {

     if (event.keyName == 'Enter') {

     press_enter ()}

})

 

dlg.show()   

 

// My Script!

function comando(){   

  alert("To apply")   

}

Translate
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
Contributor ,
May 29, 2017 May 29, 2017

Hi smithcgl9043167 Very good guy saw, how wonderful! It worked perfectly well. Thank you very much!

Translate
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
Community Expert ,
May 29, 2017 May 29, 2017
LATEST

Ps-Design​

Please read my last posting again:

"… but not with target PS or Illu, sorry …"

For Enter and ESC you can also use the dlg.defaultElement

smithcgl9043167​,

good finding.

Translate
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