Link to home
Start Free TrialLog in
Avatar of burevestnik
burevestnik

asked on

Tab key

How to intercept a Tab Key for a listbox and Textbox controls? KeyPress, KeyDown and KeyUp events do not recognize Tab key at all.
ASKER CERTIFIED SOLUTION
Avatar of jlowrance
jlowrance

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wpd
wpd

Or you can subclass the window and trap all events _before_ VB gets a chance to process and/or discard them. I'll tell you more if you're interested.
wpd - Yes, I'm interested.  Always have an ear open for learning...
Email me at jlowrance@usa.net if you wish to continue outside of this forum...
See below. Should add plenty of error checking and such, but this code will let you peek at all window messages before VB gets a chance to process them.
 
Const GWL_WNDPROC = -4

Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpFunc&, ByVal hWnd&, ByVal Msg&, ByVal wParam&, ByVal lParam&) as Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd&, ByVal index&, ByVal dwNewLong&) as Long

Dim lSavWndProc as Long

Private Sub Form_Load()

' subclass the window
lSavWndProc = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf myWindowProc)

End Sub

Private Sub Form_Unload()

 ' remove the hook
 Call SetWindowLong (Me.hWnd, GWL_WNDPROC, lSavWndProc)

End Sub

' our custom window proc
Function myWindowProc(ByVal hWnd&, ByVal msg&, ByVal wParam&, ByVal lParam&) as Long

if msg = ... ' Test for the message that interests you
'... do something with it

' pass the message for normal processing
myWindowProc = CallWindowProc (lSavWndProc, hWnd, msg, wParam, lParam)

End Function

Avatar of burevestnik

ASKER

I believe I found solution myself. I just had to change TabIndex property to do what I need to do. Thanks everyone who responded.