[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Catch KeyPress only once.

Posted on 2013-01-19
4
Medium Priority
?
698 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and 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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

656 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