10

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.

William
  • 7,595
  • 2
  • 22
  • 70
  • 1
    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. – C. E. Aug 25 '13 at 17:57
  • 1
    These are not events for EventHandler but events in GUIKit. – Michael E2 Aug 26 '13 at 00:33

1 Answers1

1

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.

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • 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. – William Feb 28 '18 at 03:26
  • @William something like that, maybe better "the answer is no but it may be that someone will provide a case specific trick". – Kuba Feb 28 '18 at 07:01