6
$\begingroup$

As you can see in the documentation of CreateDialog:

If the dialog contains no DefaultButton or CancelButton, pressing Enter or Esc will close the dialog without taking any other action.

In dialogs created with CreateDialog, pressing Enter is effectively equivalent to clicking the DefaultButton, and Esc to clicking the CancelButton.

For example I have an InputField, but when I press Esc key to write any expression, the dialog closes.

I'm trying with the fuction:

CreateDialog[Overlay[{DefaultButton[], CancelButton[], InputField[]},{3}, 3]]

But it does not work.

How can change this behavior in Dialog?

$\endgroup$

1 Answer 1

8
$\begingroup$

You can overwrite specific NotebookEventActions which are responsible for that:

CreateDialog[
 Overlay[{DefaultButton[], CancelButton[], InputField[]}, {3}, 3], 
 NotebookEventActions -> {
   "EscapeKeyDown" :> {}, 
   "ReturnKeyDown" :> {},
   PassEventsDown -> True
 }
]

PassEventsDown -> True allows "\[AliasDelimiter]" to appear in the InputField after pressing Esc.

$\endgroup$
4
  • $\begingroup$ Ok thank you, the function its ok, but i need write simbols, for example the simbol omega, this its write whit Esc omega Esc in mathematica. I solved the problem with: CreateDialog[InputField[], NotebookEventActions -> {"WindowClose" :> {}}]. $\endgroup$
    – ivan
    Commented Jun 6, 2016 at 23:23
  • $\begingroup$ Sorry the first comment is incomplete. I removed. :) $\endgroup$
    – ivan
    Commented Jun 6, 2016 at 23:26
  • $\begingroup$ @ivan I don't understand, esc+omega+esc is the same as esc+o+esc, at least on my system. $\endgroup$
    – Kuba
    Commented Jun 7, 2016 at 6:18
  • $\begingroup$ Yes, its de same. thank you for your healp :) $\endgroup$
    – ivan
    Commented Jun 7, 2016 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.