Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect TAB Key

Status
Not open for further replies.

ahhuang

Programmer
Apr 1, 2002
61
0
0
SG
In VB6,
i like to detect TAB Key but unable to do so..
i tried 2 method already..

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
MsgBox "HiHi"
End If
End Sub

or

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyTab Then
MsgBox "Hihi"
End If
End Sub

can anyone help me in this??
Regards Ahhuang
 
Is there a keyPreview prpoerty in the form that you can set to true? If so, the above code should work after setting the keyPreview to true
 
Instead of:

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyTab Then
MsgBox "Hihi"
End If
End Sub

Do:

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
msgBox KeyCode
End Sub

First and press the key you want. After you get the number that belongs to the pressed key, for example 10 do:

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = 10 Then
MsgBox "Hihi"
End If
End Sub


Hope this helps!
 
The only way to get the TAB key in the KeyDown, KeyPress, or KeyUp events is to have TabStop=False for all other controls. The TabStop for the control that has the focus can be true or false. An exception is the Rich Text Box dependding on the version of the underlying Rich Text DLL's. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
It is quite simple to detect the tab key using GetKeyState. See article #277916 in MS Knowledge Base. Do note that you must use the Validate event, not KeyUp, KeyDown or KeyPress.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top