3
$\begingroup$

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.

$\endgroup$
  • 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 '15 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 '15 at 18:12
  • 1
    $\begingroup$ The text is in an InputField in a dynamicModule. $\endgroup$ – Ricsi Nincs Aug 27 '15 at 9:14
2
$\begingroup$

The following copies the selected text to the clipboard

DynamicModule[{},
 EventHandler[Dynamic@InputField[x], 
             {"MouseUp" :> 
              FrontEndExecute[FrontEndToken[FrontEnd`SelectedNotebook[], "Copy"]]}, 
              PassEventsDown -> True]]
$\endgroup$
2
$\begingroup$

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

 EventHandler[
  InputField[],
  {"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.

$\endgroup$

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.