10
$\begingroup$

How might I detect when an InputField comes into focus?

For example ideally something like this would work.

EventHandler[
 InputField["default", String], {
  "FocusGained" :> (MessageDialog["Focus"]),
  "FocusLost" :> (MessageDialog["unFocus"]),
  "Focus" :> (MessageDialog["Focus"])
  }
 ]

After reading this question I assumed "FocusGained,FocusLost or Focus" would do something but I haven't had any luck just yet.

$\endgroup$
2
  • 1
    $\begingroup$ A workaround may be to use "MouseClicked" to trigger "focus" and then use ControllerState["Button 1"] to trigger "unfocus", using "MouseEntered" and "MouseExited" to determine if the click was inside our outside the input box. $\endgroup$
    – C. E.
    Aug 25, 2013 at 17:57
  • 1
    $\begingroup$ These are not events for EventHandler but events in GUIKit. $\endgroup$
    – Michael E2
    Aug 26, 2013 at 0:33

1 Answer 1

1
$\begingroup$

No, there is not anything documented that supports those events directly.

With so many folks digging up undocumented features I think it is safe to say that there isn't anything undocumented either.

There is a possibility of playing with indirect methods, e.g. listening to SelectionData etc. but I don't think it will give us a general tool, or a scalable one.

Maybe someonce will try to cook something up with this idea, meanwhile I think it is worth to take this on from an unanswered stack.

$\endgroup$
2
  • $\begingroup$ I'm assuming "meanwhile I think it is worth to take this on from an unanswered stack" means there is no sense in leaving this question unanswered when there is certainly not a clear answer. $\endgroup$
    – William
    Feb 28, 2018 at 3:26
  • $\begingroup$ @William something like that, maybe better "the answer is no but it may be that someone will provide a case specific trick". $\endgroup$
    – Kuba
    Feb 28, 2018 at 7:01

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.