event KeyDown (KeyCode as Integer, Shift as Integer)

Occurs when the user presses a key while an object has the focus.

 TypeDescription 
   KeyCode as Integer An integer that represent the key code.  
   Shift as Integer An integer that corresponds to the state of the SHIFT, CTRL, and ALT keys at the time of the event. The shift argument is a bit field with the least-significant bits corresponding to the SHIFT key (bit 0), the CTRL key (bit 1), and the ALT key (bit 2). These bits correspond to the values 1, 2, and 4, respectively. Some, all, or none of the bits can be set, indicating that some, all, or none of the keys are pressed. For example, if both CTRL and ALT are pressed, the value of shift is 6.  

Use KeyDown and KeyUp event procedures if you need to respond to both the pressing and releasing of a key. You test for a condition by first assigning each result to a temporary integer variable and then comparing shift to a bit mask. Use the And operator with the shift argument to test whether the condition is greater than 0, indicating that the modifier was pressed, as in this example:

ShiftDown = (Shift And 1) > 0
CtrlDown = (Shift And 2) > 0
AltDown = (Shift And 4) > 0

In a procedure, you can test for any combination of conditions, as in this example:
If AltDown And CtrlDown Then

The EditChange event notifies your application that the user alters the control's edit. Use the SelectionChanged event to notify your application that the user changes the selected item. Use the EditText property to determine the text of the edit control. Use the DropDown method to show programmatically the control's drop down portion. By default, the control shows the drop down portion of the control when the user presses the F4 key. Use the Key property to replace the default action when a certain key is pressed.

The following VB sample shows the control's drop down portion when the user presses the F3 key:

Private Sub ComboBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    If (KeyCode = vbKeyF3) Then
        With ComboBox1
            .DropDown() = True
        End With
    End If
End Sub

The following C++ sample shows the control's drop down portion when the user presses the F3 key:

void OnKeyDownCombobox1(short FAR* KeyCode, short Shift) 
{
	if ( *KeyCode == VK_F3 )
	{
		COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR;
		m_combobox.SetDropDown( vtMissing, TRUE );
	}
}

The following VB.NET sample shows the control's drop down portion when the user presses the F3 key:

Private Sub AxComboBox1_KeyDownEvent(ByVal sender As Object, ByVal e As AxEXCOMBOBOXLib._IComboBoxEvents_KeyDownEvent) Handles AxComboBox1.KeyDownEvent
    If (Convert.ToUInt32(e.keyCode) = Convert.ToUInt32(Keys.F3)) Then
        With AxComboBox1
            .set_DropDown(True)
        End With
    End If
End Sub

The following C# sample shows the control's drop down portion when the user presses the F3 key:

private void axComboBox1_KeyDownEvent(object sender, AxEXCOMBOBOXLib._IComboBoxEvents_KeyDownEvent e)
{
	if (Convert.ToUInt32(e.keyCode) == Convert.ToUInt32(Keys.F3))
		axComboBox1.set_DropDown(true);
}

The following VFP sample shows the control's drop down portion when the user presses the F3 key:

*** ActiveX Control Event ***
LPARAMETERS keycode, shift

if ( keycode = 114 ) && F3
	with thisform.ComboBox1
		.Object.DropDown("") = .t.
	endwith
endif

 


Send comments on this topic.
© 1999-2010 Exontrol.COM, Software. All rights reserved.