3

When InputField was set to String, I found a way to change the line of the sentence by pressing Enter. In this case, how does the calculation run when the Shift+Enter key is pressed?

EventHandler[ InputField[Dynamic@text, String, ContinuousAction -> True, 
              ImageSize -> {300, 100}], {"ReturnKeyDown" :> Paste["\n"]}]

enter image description here

I want to write a few lines of instruction in the InputField and run it when I press Shift+Enter.

Milk
  • 1,688
  • 10
  • 9

1 Answers1

4

Combining your attempt with the technique from this answer:

multilineInput[Dynamic[text_]] := DynamicModule[
  {innerText = If[StringQ@text, text, ""]},
  EventHandler[
   InputField[Dynamic@innerText, String],
   {
    "ReturnKeyDown" :> If[! CurrentValue["ShiftKey"], Paste["\n"]],
    {"MenuCommand", 
      "HandleShiftReturn"} :> {text = innerText}, {"MenuCommand", 
      "EvaluateCells"} :> {text = innerText}
    },
   PassEventsDown -> False
   ]
  ]

text = "Hello world"; multilineInput[Dynamic@text] Dynamic@text

enter image description here

Lukas Lang
  • 33,963
  • 1
  • 51
  • 97