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$
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$
  • $\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 Jun 6 '16 at 23:23
  • $\begingroup$ Sorry the first comment is incomplete. I removed. :) $\endgroup$ – ivan Jun 6 '16 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 Jun 7 '16 at 6:18
  • $\begingroup$ Yes, its de same. thank you for your healp :) $\endgroup$ – ivan Jun 7 '16 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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