Solved

Catch KeyPress only once.

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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