Solved

Catch KeyPress only once.

Posted on 2013-01-19
4
681 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
  • 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now