Skip to main content
Inspiring
April 30, 2023
Pergunta

pressing the Esc key when using dialog Confirm()

  • April 30, 2023
  • 2 respostas
  • 1376 Visualizações
Hello everyone.

var way = confirm(" AAA ?");
if (way) alert("Y")
else alert("N")

When executing the script, it doesn't matter which key is pressed "Esc" or "N". It will still show "N". I want that when I press "Esc", the execution of the script is completed ... Then it will be possible to put three states into such a dialog .. Is it possible ???
Este tópico foi fechado para respostas.

2 Respostas

Legend
April 30, 2023
var way = confirm(" AAA ?");

if (ScriptUI.environment.keyboardState.keyName == "Escape") alert ("Escape");

else if (way) alert("Y")
else alert("N")
AnyONAutor
Inspiring
May 2, 2023

Valorous Hero  !!!

Legend
April 30, 2023

No. But you can write your own dialog box and handle button clicks the way you want.

 

var result = ['yes', 'esc', 'no']
alert (result[createDialog('test question?')-1])
function createDialog(text) {
    var w = new Window('dialog {text: "Test confirm window"}'),
        stInput = w.add('statictext', undefined, text),
        gBn = w.add('group {orientation: "row", alignChildren: ["left","center"]}'),
        bnOk = gBn.add('button', undefined, 'Yes', { name: 'bnOk' }),
        bnCancel = gBn.add('button', undefined, 'No', { name: 'bnCancel' });
    bnOk.active= true;
    bnOk.onClick = function () {  w.close(1)  }
    bnCancel.onClick = function () { w.close(3)  }
     return w.show();
}

 

 

 
 

 

 

AnyONAutor
Inspiring
April 30, 2023

thanks for the answer JAZZ-Y!!!

I'm trying to assign the result of the createDialog function to a variable.

 

var cosist = result[createDialog('test question?') - 1]

 

I need to branch my code to get it to work.

 

 

if (cinsist == "Yes") {
  alert(1)  
} else if (cinsist == "No") {
    alert(2)    
} else if (cinsist == "Esc") {
    throw "stop";
}

 

But that trick doesn't work...

 

cinsist is undefined

 

How to make such an appointment?

Legend
April 30, 2023

You are using different variable names.

 

cosist

 

cinsist