event KeyDown (ByRef KeyCode as Integer, Shift as Integer)
Occurs when the user presses a key while an object has the focus.

TypeDescription
KeyCode as Integer (By Reference) 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 Change event to notify your application that the user changes the cell's value. Use the Editing property to determine whether the control is in edit mode. 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

Syntax for KeyDown event, /NET version, on:

private void KeyDown(object sender,ref short KeyCode,short Shift)
{
}

Private Sub KeyDown(ByVal sender As System.Object,ByRef KeyCode As Short,ByVal Shift As Short) Handles KeyDown
End Sub

Syntax for KeyDown event, /COM version, on:

private void KeyDownEvent(object sender, AxEXGRIDLib._IGridEvents_KeyDownEvent e)
{
}

void OnKeyDown(short FAR* KeyCode,short Shift)
{
}

void __fastcall KeyDown(TObject *Sender,short * KeyCode,short Shift)
{
}

procedure KeyDown(ASender: TObject; var KeyCode : Smallint;Shift : Smallint);
begin
end;

procedure KeyDownEvent(sender: System.Object; e: AxEXGRIDLib._IGridEvents_KeyDownEvent);
begin
end;

begin event KeyDown(integer KeyCode,integer Shift)
end event KeyDown

Private Sub KeyDownEvent(ByVal sender As System.Object, ByVal e As AxEXGRIDLib._IGridEvents_KeyDownEvent) Handles KeyDownEvent
End Sub

Private Sub KeyDown(KeyCode As Integer,Shift As Integer)
End Sub

Private Sub KeyDown(KeyCode As Integer,ByVal Shift As Integer)
End Sub

LPARAMETERS KeyCode,Shift

PROCEDURE OnKeyDown(oGrid,KeyCode,Shift)
RETURN

Syntax for KeyDown event, /COM version (others), on:

<SCRIPT EVENT="KeyDown(KeyCode,Shift)" LANGUAGE="JScript">
</SCRIPT>

<SCRIPT LANGUAGE="VBScript">
Function KeyDown(KeyCode,Shift)
End Function
</SCRIPT>

Procedure OnComKeyDown Short llKeyCode Short llShift
	Forward Send OnComKeyDown llKeyCode llShift
End_Procedure

METHOD OCX_KeyDown(KeyCode,Shift) CLASS MainDialog
RETURN NIL

void onEvent_KeyDown(COMVariant /*short*/ _KeyCode,int _Shift)
{
}

function KeyDown as v (KeyCode as N,Shift as N)
end function

function nativeObject_KeyDown(KeyCode,Shift)
return

The following VB sample starts editing the cell is the user presses the F4 key, and AutoEdit property is False. 

Private Sub Grid1_KeyDown(KeyCode As Integer, Shift As Integer)
    ' Edits the focused cell once that user presses the F4 key
    If (KeyCode = vbKeyF4) Then
        Grid1.Edit
    End If
End Sub

The following VB sample advances to the next field, when the user presses the ENTER key ( the sample is useful when the current editor is a simple edit control ) :

Private Sub Grid1_KeyDown(KeyCode As Integer, Shift As Integer)
    If (KeyCode = vbKeyReturn) Then
        KeyCode = vbKeyDown
    End If
End Sub

The following C++ sample starts editing the focused cell when user presses the ENTER key, ( AutoEdit property is False):

void OnKeyDownGrid1(short FAR* KeyCode, short Shift) 
{
	if ( *KeyCode == VK_RETURN )
	{
		COleVariant vtMissing; V_VT( &vtMissing) = VT_ERROR;
		if ( m_grid.GetEditing() == 0 )
			m_grid.Edit( vtMissing );
	}
}

The following VB.NET sample starts editing the focused cell when user presses the ENTER key, ( AutoEdit property is False):

Private Sub AxGrid1_KeyDownEvent(ByVal sender As Object, ByVal e As AxEXGRIDLib._IGridEvents_KeyDownEvent) Handles AxGrid1.KeyDownEvent
    If (Convert.ToUInt32(e.keyCode) = Convert.ToUInt32(Keys.Enter)) Then
        AxGrid1.Edit(Nothing)
    End If
End Sub

The following C# sample starts editing the focused cell when user presses the ENTER key, ( AutoEdit property is False):

private void axGrid1_KeyDownEvent(object sender, AxEXGRIDLib._IGridEvents_KeyDownEvent e)
{
	if (Convert.ToUInt32(e.keyCode) == Convert.ToUInt32(Keys.Enter))
		axGrid1.Edit(null);
}

The following VFP sample starts editing the focused cell when user presses the ENTER key, ( AutoEdit property is False):

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

if ( keycode = 13 )
	thisform.Grid1.Object.Edit("")
endif