how do we capture the Tab Key Press event in a text box

how do we capture the Tab Key Press event in a text box

Post by rchennat » Thu, 04 Nov 2004 06:21:01


'By default, VB uses the Tab key to move focus between controls.
'To capture the tab key you will need to use
'windows API GetAsyncKeyState

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vVirtKey
As Long) As Integer


Private Function KeyPressed(iKey As Integer) As Boolean
If GetAsyncKeyState(iKey) < 0 Then
KeyPressed = True
Else
KeyPressed = False
End If
End Function

Private Sub txtTab_LostFocus()
If KeyPressed(vbKeyTab) = True Then
MsgBox "TAB Key Pressed"
End If
End Sub