Solved

Catch KeyPress only once.

Posted on 2013-01-19
4
693 Views
Last Modified: 2013-01-21
Hi,

I'm creating a multitabbed webbrowser, and want to get better control, when tabbing through the tabs.
For that i have created a Sub to catch the Control + Tab keyboard event, but it seems that I'm catching the keypresses continuously, instead of once.

The code looks like this:

Private Sub Browser_PreviewKeyDown(sender As Object, e As System.Windows.Forms.PreviewKeyDownEventArgs)
        If (e.KeyCode = Keys.Tab AndAlso e.Modifiers = Keys.Control) Then
            ' Control + Tab pressed
            Dim tnt = ActiveTabPage
            tnt = tnt + 1
            If tnt = 10 Then tnt = 0
            TabControl1.SelectedIndex = tnt
        End If
End Sub

I would expect that I will need to catch the keyup event as well, but I haven't been succesfull in implementing it with the code above.

Suggestions would be very much appreciated.

BR
Naan_PLS
0
Comment
Question by:NaanPLS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 38800792
Did you try using the PreviewKeyUp instead?
0
 

Author Comment

by:NaanPLS
ID: 38801653
I tried, But it seems not to be implementet:

'PreviewKeyUp' is not an event of 'System.Windows.Forms.WebBrowser'.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38801836
In that case, you would need to do some timing yourself. If the current key is same as previous and is pressed within a given time period (such as 500ms) then ignore it.
0
 

Author Comment

by:NaanPLS
ID: 38802243
Thanks, that did the trick :-)

Private Sub Browser_PreviewKeyDown(sender As Object, e As System.Windows.Forms.PreviewKeyDownEventArgs)
Dim ntmr As Date = Now
        Dim tmrdiff As TimeSpan = ntmr - Me.tmr
        If tmrdiff.Milliseconds < 100 Then Return
        If (e.KeyCode = Keys.Tab AndAlso e.Modifiers = Keys.Control) Then
            ' Control + Tab pressed
            Dim tnt = ActiveTabPage
            tnt = tnt + 1
            If tnt = 10 Then tnt = 0
            TabControl1.SelectedIndex = tnt
        End If
Me.tmr = Now
End Sub
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question