KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Detecting keystrokes
PRODUCT: 4D | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: March 25, 1999

In the past, the only way to detect when the user typed something was by using an ON EVENT filter. Now with the introduction of 4D 6.5, you can use a new form event called On After Keystroke along with a new command called Get edited text.

Given an object called vtFind, you could have a method associated with that object that performs a query based upon what the use types, as they type it.

Examine the following code segment:

  ` Object Method: vtFind
If (Form event=On After Keystroke )
 vtFindText:=Get edited text
 If (vtFindText#"")
  QUERY([Recipes];[Recipes]Recipe=vtFindText+"@")
  SELECTION TO ARRAY([Recipes]Recipe;aRecipeList)
  UNLOAD RECORD([Recipes])
 Else
  EDUCE SELECTION([Recipes];0)
  ARRAY STRING(50;aRecipeList;0)
 End if
End if

Here you can see that vtFindText gets the text of what the user has typed so far into the variable vtFind as they type. What is important to note is that this event is occurring before the user tabs out. Normally, the variable vtFind would NOT contain any value until the user tabs or clicks out of that object.
For more examples of how to use this, including examples of using Clairvoyance typing such as the kind you see in Quicken, Netscape or IE, see my upcoming technical note.