KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Selectively ignoring trapped keys
PRODUCT: 4D | VERSION: 14.0 | PLATFORM: Mac & Win
Published On: March 3, 2014

An easy way to trap keys is to use an invisible button with a keyboard shortcut (properties list). When the assigned key is pressed, it will then perform the method inside the button. To ignore these keys in certain areas of the form, enabling and disabling the invisible button is a good approach.
For instance, suppose there is a form with 3 text fields(vSearch,vDescription, and vComments) and an invisible button.

The enter key is tied to the shortcut in the invisible button and should only activate when inside the text field vSearch. To prevent the shortcut in vDescription and vComments, place the following code in the text field vSearch:

Case of
  : (Form event=On Getting Focus)
   ENABLE BUTTON(InvisibleButton)
  : (Form event=On Losing Focus)
   DISABLE BUTTON(InvisibleButton)
End case

This will enable the invisible button when the focus is on the first text field, and disable it when it loses the focus. A final step is to make sure that vSearch has the events On Getting Focus and On Losing Focus checked in the properties list.