473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How to capture tab key presses

Don
It took me a while to find this code, so I decided to post it here for
others who might also be looking for a way to trap tab key presses. You can
extend a control and place this code in it to raise a custom TabKeyDown
event. Here is an example of how you might extend a TextBox control to
provide this event:
Public Class TextBoxEx
Inherits TextBox

Const WM_KEYDOWN As Integer = &H100
Const WM_SYSKEYDOWN As Integer = &H104

Public Event TabKeyDown(ByVal CtrlPressed As Boolean, _
ByVal ShiftPressed As Boolean)

Protected Overrides Function ProcessCmdKey(ByRef msg As Message, _
ByVal keyData As Keys) As Boolean

' If a key or system key is pressed...
If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then

' If the tab key is pressed...
If keyData = Keys.Tab Then

' The user pressed the tab key (without holding ctrl,
' shift, or alt)
RaiseEvent TabKeyDown((keyData And Keys.Control) = _
Keys.Control, (keyData And Keys.Shift) = Keys.Shift)

' If the tab key was pressed along with one or more
' other system keys...
ElseIf (keyData And Keys.Tab) = Keys.Tab Then

' The user held ctrl shift or alt and pressed the tab key
' Note: I don't bother to trap for the Alt key because
' Alt-Tab switches focus to another app and yours
' will not receive the message anyway.
RaiseEvent TabKeyDown((keyData And Keys.Control) = _
Keys.Control, (keyData And Keys.Shift) = Keys.Shift)

End If

End If

' Let base class handle the key press
Return MyBase.ProcessCmdKey(msg, keyData)

End Function

End Class
- Don
Nov 21 '05 #1
2 7028
Don,

Is this not easier?

\\\
Private Sub TextBox1_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles TextBox1.KeyUp
If e.KeyData = Keys.Tab Then
MessageBox.Show("Hello Don")
End If
End Sub
///
Nov 21 '05 #2
Don
I wish it were that easy, but pressing the tab key does not fire the
KeyUp/KeyDown/KeyPress events.

- Don
"Cor Ligthert" <no************@planet.nl> wrote in message
news:ez*************@TK2MSFTNGP14.phx.gbl...
Don,

Is this not easier?

\\\
Private Sub TextBox1_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles TextBox1.KeyUp
If e.KeyData = Keys.Tab Then
MessageBox.Show("Hello Don")
End If
End Sub
///

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: aimee | last post by:
Hi. Is there a way to capture the events fired in a PrintDialog? I would like to capture when the user presses "Print" so I can do some cleanup. The asp.net (IE6) application I'm working on has 6...
7
by: (Pete Cresswell) | last post by:
I've got KeyDown coding and it fires when other keys are pressed, but when Enter is pressed, nothing. I'd like to support the (standard?) Windows behavior of executing DblClick processing when...
2
by: orekinbck | last post by:
Hi There In a C# windows app in .NET 2003, I would like to capture when the user is within a certain text box and holds down shift then presses tab. Atm, my code is: protected override bool...
2
by: petedawn | last post by:
guys, i want to capture all the function key presses from F1 to F12. now i want that when the user presses F1 from within the browser i should display a alert window saying that they have...
10
by: amiga500 | last post by:
Hello, I have one basic simple question. When I have multiple records in the datagrid as follows: Code Product 1 Product 2 Product 3 11111 A B C...
6
by: trbjr | last post by:
Hello experts, I want to describe a project design and then ask some questions at the end. There is no code in this discussion, just symbols to illustrate an idea. Let S stand for a screen...
1
xarzu
by: xarzu | last post by:
How do I capture the event in a CEdit control when the user presses enter or return in a dialog box? I have so far figured out how to disable the event when the user hits return which normally would...
5
by: sourav08 | last post by:
Hello, I'm developing a website using PHP, Javascript and MySQL. I have a login form with a couple of textboxes and a login button. What I want to do is capture the Enter key so that when the...
4
by: Vighneswar | last post by:
Hi All Can anybody please suggest me in this regard that I need to capture the keystrokes on all the word processors (Ms Word, Excel .. Etc), text editors (Notepad .. Etc) and suggest nearer...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.