MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

EventHandler problem

  • To: mathgroup at
  • Subject: [mg88632] EventHandler problem
  • From: "J. McKenzie Alexander" <jalex at>
  • Date: Sat, 10 May 2008 06:53:47 -0400 (EDT)

I'm trying to design a custom InputField that indicates whether or not  
the user has pressed Return to submit the changes. It's a simple  
design: a red or green disk is drawn to the right of the InputField to  
indicate the state.

Here's the definition of the disks:

	red = Graphics[{Green, AbsolutePointSize[12], Point[{0, 0}]},
		 ImageSize -> {20, Automatic}]

	green = Graphics[{Green, AbsolutePointSize[12], Point[{0, 0}]},
		 ImageSize -> {20, Automatic}]

Here's my first attempt at creating the InputField:

	DynamicModule[{k = 1, changed = False},
	    InputField[Dynamic[k], Number, FieldSize -> Tiny,
	     ContinuousAction -> True],
	    {"KeyDown" :> (changed = True),
	     "ReturnKeyDown" :> (changed = False)
	    PassEventsDown -> True
	   Dynamic[If[changed, red, green]]

Everything works except setting the value of changed back to False  
when the Return key is pressed. Mathematica fires the action for  
*both* "KeyDown" and "ReturnKeyDown", and the "KeyDown" action is  
invoked after the "ReturnKeyDown" action. (This happens regardless of  
whether one uses {"KeyDown" :> (...), "ReturnKeyDown" :> (...) } or   
{"ReturnKeyDown" :> (...) "KeyDown" :> (...)} in the argument to  

I've tried detecting the value of the key by using  
CurrentValue["EventKey"] but this doesn't seem to do anything...

Any thoughts on how to solve this problem would be greatly appreciated!



Dr J. McKenzie Alexander
Department of Philosophy, Logic and Scientific Method
London School of Economics and Political Science
Houghton Street, London WC2A 2AE

Please access the attached hyperlink for an important electronic communications disclaimer:

  • Prev by Date: Re: A Mathematica implementation of SolvOpt
  • Next by Date: Re: Display commands in a package
  • Previous by thread: Re: issues with unit package
  • Next by thread: Re: EventHandler problem