The following method is a Key event handler for a custom entryfield that executes a SEEK in the current workarea as keys are pressed—an incremental search control. It checks if there are keystrokes pending in the keyboard typeahead buffer—which would happen for a fast typist—and if so, no SEEK is executed, since those pending keystrokes would immediately cause another SEEK.

function Key( nChar, nPosition )

   if nextkey( ) # 0 // If keys pending 

      return ( nChar # 255 ) // do nothing, and suppress keystroke if value is 255 

   endif 

   if nChar == 255 // If keystroke is special value 255 

      if not isblank( this.value ) 

         this.seek( ) // call control's seek( ) method to do actual SEEK 

      endif 

   else 

      if nChar >= 32 and nChar < 255 

         keyboard "{255}" // For alphanumeric keystrokes, stuff special key 255 

      endif 

   endif 

return nChar 

Like all Key event handlers, this one receives two parameters: the value of the keystroke, and the current position in the control. This method does not use the position parameter. It does use a specific keystroke, which is chosen so that it does not conflict with typical keys. That keystroke has the INKEY( ) value 255.

For an alphanumeric keystroke—that is, one that is not a control or function key—the special key is stuffed into the keyboard buffer by the KEYBOARD command. This causes the Key event to be fired again, after the key that was actually typed goes into the entryfield as usual. The Key method detects the special key and performs the SEEK, which is coded in a separate seek( ) method for modularity; that is, the SEEK behavior may be modified without changing the Key method.