by Bob Lewis (2 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 5th October 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This code captures the Tab key, in certain situations. It is especially useful with the shift key
API Declarations
nVirtKey As Long) As Integer
If GetKeyState(vbKeyTab) < 0 Then
If (GetKeyState(vbKeyShift) < 0) Then
' Shift-Tab key is pressed
GotFocusMethod = 4
Else
' Tab key is pressed
GotFocusMethod = 1
End If
ElseIf GetKeyState(vbKeyMenu) < 0 Then
' Alt key is pressed (hotkey activation)
GotFocusMethod = 2
ElseIf GetKeyState(vbLeftButton) < 0 Then
' mouse left button is pressed
GotFocusMethod = 3
End If
End Function
' Example on form
' use this in a _lostFocus sub
Private Sub txtEmployee_LostFocus(Index As Integer)
If GotFocusMethod = 4 And Index = 0 Then
'code goes here
End If
End Sub
No comments have been posted about This code captures the Tab key, in certain situations. It is especially useful with the shift key. Why not be the first to post a comment about This code captures the Tab key, in certain situations. It is especially useful with the shift key.