Copy link to clipboard
Copied
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.
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")
}
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
...Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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")
}
Copy link to clipboard
Copied
Hi smithcgl9043167 Very good guy saw, how wonderful! It worked perfectly well. Thank you very much!
Copy link to clipboard
Copied
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
good finding.