devxlogo

OnKey()

OnKey()

Question:
What is the OnKey() method?

Answer:
The OnKey() method is a new method introduced with OPO version 1.0.16. The OnKey() method is triggered for an object whenever a user enters a keystroke into the object at run-time.

The OnKey() method has three parameters: the keychar parameter, the keycode parameter and the shift parameter. The keychar, as the name implies, is the keystroke entered by the user. The keycode is a constant that indicates the type of keystroke entered – such as KEYCODE_CHAR for any alphanumeric or punctuation character, KEYCODE_DELETE for the delete key, etc. The shift parameter indicates whether the Shift or Control keys were pressed with the keystroke.

If you return True from the OnKey() method, you prevent the default processing of the keystoke, which includes setting the Value of the object. If you return nothing or False, the default keystroke processing does take place.

You can use the OnKey() method for a wide variety of purposes, such as monitoring user entries, bringing up other forms that contain context sensitive information or intercepting and replacing keystokes entered.

Version 1.0.16 of Power Objects also has a ChildOnKey() method, which works at the container level.

You can see an example of the OnKey() method at work if you look at the question on hiding passwords elsewhere in this area.

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist