Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to make the Return Key move the insertion point to the end of the input field's text. Please see the example below for the problem I am facing. Namely, when the return key is pressed, the input field's text is updated but the insertion point is not moved.

DynamicModule[{thing = "foo"}, nb = EvaluationNotebook[];EventHandler[InputField[Dynamic@thing,String], {"ReturnKeyDown" :> (thing = thing <> "bar";SelectionMove[nb, Next, Word])}]]
share|improve this question
up vote 1 down vote accepted

Figured this one out. It is basically the same problem described here and essentially answered here.

The actions in the EventHandler are calculated on the preemptive link. In order to make the EventHandler act as a Button when Method->"Queued", DynamicWrapper can be used:

DynamicModule[{thing="foo",returnkeydown=False},nb = EvaluationNotebook[];DynamicWrapper[EventHandler[InputField[Dynamic[thing],String],{"ReturnKeyDown":>(thing= thing<>"bar";returnkeydown=True)}],If[returnkeydown,returnkeydown=False;SelectionMove[nb,Next,Word]],SynchronousUpdating->False]]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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