Wrox Programmer Forums
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 4th, 2004, 07:15 AM
Registered User
 
Join Date: Nov 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Tab Key event

I want show the message if the client press the Tab key. can any one guide me how to capture the tab key event.
 
Old November 4th, 2004, 07:24 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

I assume you are using VB 6.0. You need to programme the keydown event of the control.

The code is :

If KeyCode=vbKeyTab then
    Msgbox "Tab key pressed"
    ' do necessary actions
    KeyCode=0 'This will set the key code to null. Otherwise, focus will go to the control with next tab index.
End If
 
Old November 4th, 2004, 08:01 AM
Registered User
 
Join Date: Nov 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Madhu,

I tried like this but it is not working. I took 2 text boxes and applied this code. but it's not working. can you give me other way to achieve this.


thanks

srinivas
 
Old November 4th, 2004, 08:24 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

Could you please post your code piece ?
 
Old November 4th, 2004, 10:52 AM
Registered User
 
Join Date: Nov 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyTab Then
    MsgBox "Client 1"
    KeyCode = 0
End If
End Sub

Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyTab Then
    MsgBox "Client 2"
    KeyCode = 0
End If
End Sub
 
Old November 4th, 2004, 04:29 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Windows intercepts the TAB key if in the same form there is more than one component that has the TabStop property set (like in your case, you have Text1 and Text1). The reason why is that Windows uses the TAB to switch the focus.
The only way to get the tab event is to use a keyboard application message hook (via SetWindowsHookEx)

BTW why do you want to do that?

Marco





Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot get panel to respond to tab key AndrewH Java GUI 0 January 29th, 2007 04:41 PM
TAB KEY working together KEY PRESS event thomaz C# 4 August 20th, 2006 02:47 PM
using enter key as tab but not in multiline listbo sdduffer General .NET 1 March 30th, 2005 02:29 AM
Tab Key aliarifpk General .NET 0 February 26th, 2004 08:47 AM
Using the TAB ORDER with ENTER KEY ? thomaz C# 0 September 10th, 2003 08:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.