From: Jaebum Jung on 3 Apr 2010 06:58 You could try this with EventHandler msgs={};DynamicModule[{ins=""},EventHandler[InputField[Dynamic[ins],String,ContinuousAction->True],{"ReturnKeyDown":>(msgs=AppendTo[msgs,ins];ins="";)}]] Dynamic[Column(a)msgs] - Jaebum On 4/2/10 5:20 AM, mkr wrote: > I am trying to set up some interactive code where I issue short > instruction strings to drive some additional dynamic code. > > My hope was to use an InputField into which I could continuously type > these short instructions, with a given character sequence ("do" in the > code below) acting as the trigger (I was guessing that using the > [Enter] key might not work). > > There are a couple of immediate problem behaviors that I observe: > first, when InputField input contains spaces, the cursor keeps getting > moved to inside of the string, second, after ending a string with > "do", the cursor ends up to the right of the InputField, requiring a > [<-] keypress to get the cursor back into the InputField. > > I am using 7.0.1 on XP. Code follows: > > > > msgs={}; > procstring[ins_String]:=If[StringLength[ins]>1&&StringTake[ins, > {-2,-1}]=="do",AppendTo[msgs,StringTake[ins,{1,-3}]];"",ins] > > FullForm(a)procstring["process thisdo"]; > FullForm(a)procstring["and thisdo"]; > FullForm(a)procstring["but not this"]; > msgs > > ins=""; > InputField[Dynamic[ins,(ins=procstring[#])&],String,ContinuousAction- > >> True] >> > Dynamic[Column(a)msgs] > > > > Any help fixing this approach, or with some other technique for > achieving the same general sort of input mechanism by another > approach, would be greatly appreciated. > > Thanks, > > Miles > >
|
Pages: 1 Prev: convert txt to binary file Next: Combining elements of a list |