Key Press

The KeyPress event occurs when you press and release a key or a key combination. The KeyPress event happens when there are no controls on the form or if the form's KeyPreview property is set to Yes. The KeyPress event responds only to the ANSI characters generated by the keyboard. This event can be cancelled by setting the KeyAscii argument to zero (0).

The event procedure in Hands-On 24-16 prints the ASCII code and the value of the pressed key in the Immediate window. Upon pressing the Escape key (KeyAscii 27), the form will close.

0 0

Post a comment