I want to do the following:

Given a text in a Mathematica dynamic module "at runtime". If some text is selected with the cursor/mouse, after the mouse button release, get the selected text.

Thank you for your help in advance.

  • 1
    $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, 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, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Aug 26, 2015 at 17:16
  • $\begingroup$ How is the text presented? In a text cell printed from inside a dynamic module? Can you give an example? $\endgroup$
    – C. E.
    Aug 26, 2015 at 18:12
  • 1
    $\begingroup$ The text is in an InputField in a dynamicModule. $\endgroup$
    – ricsirke
    Aug 27, 2015 at 9:14

2 Answers 2


The following copies the selected text to the clipboard

             {"MouseUp" :> 
              FrontEndExecute[FrontEndToken[FrontEnd`SelectedNotebook[], "Copy"]]}, 
              PassEventsDown -> True]]

The text is stored (upon releasing the mouse button) in the variable val with this code:

  {"MouseUp" :> (val = CurrentValue["SelectionData"])},
  PassEventsDown -> True

It should work in other contexts as well besides InputField, as I noted in my comment it is not clear from your question what the context is.


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.