# Asking for input in an event handler

Why won't

EventHandler["text", {"MouseClicked" :> (output = Input[];)}]


work?

When I click "text" the kernel hangs.

-
can you expand a little more on what you're trying to do? –  kale Aug 24 '12 at 15:11
The real application would be something like, clicking in a graphics object, and saving the coordinates and a label that I input using Input[]... –  Peter Aug 24 '12 at 15:13
Is that code what you've been using? It contains an error: "MouseClicked" > action should be "MouseClicked" -> action. –  rcollyer Aug 24 '12 at 15:15
I use "MouseClicked" :> action, I corrected the error –  Peter Aug 24 '12 at 15:26
Welcome to Mathematica.SE! Let me remind you three things we usually do here: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the FAQs! 3) When you see good Q&A, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign –  Vitaliy Kaurov Aug 25 '12 at 8:33

You are facing an issue similar to described here . The problem is Button has option Method -> "Queued" and EventHandler does not have anything similar. Here is a way around it:

DynamicModule[{output = "click to change"}, Button[Dynamic[output],
output = InputString["Enter new text", "click to change"],
Method -> "Queued", Appearance -> "Frameless"]]


If you just must use EventHandler, then CreateDialog is a work around:

output = "click to change";
EventHandler[ Dynamic[output], {"MouseClicked" :>
CreateDialog[{TextCell["Enter new text"],
InputField[Dynamic[output], String],
DefaultButton[DialogReturn[output]]}]}]
`

-
I thought scheduled tasks could help here, but they have the same problem. Might be because scheduled tasks don't need a frontend and Input probably runs in the frontend? –  Sjoerd C. de Vries Aug 25 '12 at 7:08