Solved

Catch KeyPress only once.

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…

860 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