Trapping Keystrokes

All keyboard input for ActiveX Controls and Embedded Document Objects are routed through the standard DataFlex On_Key handler. This means that you can easily trap any keystroke and execute custom code for any COM object, just like any other DataFlex control.

The example below demonstrates how to trap keyboard input in the Calendar ActiveX control:

Object oCalendar1 is a cComCalendar

    Set Size to 104 223

    Set Location to 3 5

 

    On_Key Key_Ctrl+Key_A Send ComAboutBox

End_Object

 

This example traps the Ctrl+A key sequence inside the calendar control to display the control's internal About Box dialog.

 

A common issue with ActiveX controls is that the Enter is trapped by the view (or other parent component) the control is in, rather than the control itself. To resolve this issue, you can tell the control to directly handle the key press via on On_Key statement in the control:

On_Key Key_Enter Send Default_Key

 

See Also

Programming with COM – General Topics