Was this helpful?
KeyPress Event
The KeyPress event is triggered when an EntryField has the input focus and the user presses an ANSI key. Information about the key is stored in a KeyPressInfo object, and the KeyPress Info object is delivered to the 4GL program as the Message Object. The 4GL event code may change the keystroke or cancel it entirely by modifying the KeyPressInfo object. To discard a keystroke, set KeyPressInfo.ANSICode to zero.
This event has the following syntax:
on KeyPress [entryfieldname]
The following attributes of the Event class and FrameExec class can be used in the KeyPress event block:
MessageObject
Specifies a KeyPressInfo object that contains information about the keystroke
TriggerField
Specifies the EntryField that received the keystroke
The KeyPress event is generated only when the user presses an ANSI key. Thus, the Delete key, for example, does not cause a KeyPress event.
In the following example, every character after 'p' in the ANSI sequence is discarded. For all other characters, the next character in the sequence is substituted:
on KeyPress ef =
declare
     keyinfo        = KeyPressInfo;
enddeclare
{
     keyinfo =
       KeyPressInfo(CurFrame.MessageObject);
          if (keyinfo.Character <= 'p') then
          /*
          **  Substitute the next character in the
          **  ANSI code sequence.
          */
          keyinfo.ANSICode = keyInfo.ANSICode + 1;
    else
          /*
          **  Discard the keystroke.
          */
          keyInfo.ANSICode = 0;
    endif;
}
More information:
Last modified date: 12/20/2023