|
-
Nov 29th, 2000, 08:53 AM
#1
Hi everyone,
Does anyone know how TAB key can be detected, KeyPress event doesn't recognise it. Is there any API that would serve the purpose?
-
Nov 29th, 2000, 09:04 AM
#2
Frenzied Member
KeyPress does recognize it...
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then MsgBox "TAB!"
End Sub
Private Sub Form_Load()
KeyPreview = True
End Sub
... only at forms with only 1 or less controls.
I think there was a question about this earlier.
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 29th, 2000, 09:05 AM
#3
what r u detecting it in?
the chr# is 9 for a tab...u shouldn't have any problem detecting it!?
Code:
if KeyAscii = 9 then
Msgbpx "Tab Pressed"
end if
I just tested this with:
Code:
Private Sub Form_KeyPress(KeyAscii As Integer) ' form
Private Sub Text1_KeyPress(KeyAscii As Integer) 'text box
worked fine
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Nov 29th, 2000, 09:17 AM
#4
Frenzied Member
hey cool 
I coded a workaround.
Code:
'Set all the tabstop of all controls to false
Private Declare Function GetFocus Lib "user32" () As Long
Private Sub Form_KeyPress(KeyAscii As Integer)
Dim h&
If KeyAscii = vbKeyTab Then 'vbKeyTab = ASCII char 9, but constants look better imho (in my humble opinion ;))
h = GetFocus 'gets the handle of the control in focus.
If h = Text1.hWnd Then MsgBox "TAB AT TEXT1" 'reminds you that text1 has focus.
Text2.SetFocus 'then move on to the next control, just as normal.
End If
End Sub
Private Sub Form_Load()
KeyPreview = True 'receive all keystrokes before the controls do (sort of subclassing, but then easy :))
End Sub
Hope it helps ya, it works well for me 
[Edited by Jop on 11-29-2000 at 09:21 AM]
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 30th, 2000, 02:24 PM
#5
Thank a lot for your input, but my problem is that I have quite few controls on the form and when TAB is pressed the app doesn't go to KeyPress event. Seems like Jop's code could work in this scenario, but I haven't tried it. I worked around this problem assigning Up and Down arrow keys instead of TAB, this is more sensible solution anyway, just have to convince the client .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|