开发者

Why do I get double calls to the previewKeyDown() function in c#

I use the previewKeyDown() function for some controls in my project but they always get called twice for each key p开发者_运维问答ress. Anyone who knows how to solve this?

And is there anyway to do a global keylistener in my project?


The WebBrowser control I think has a bug, it fires that twice no matter what. I solved it via what I consider a hack, but it works. :) Mines in VB, but you get the gist of it, basically make a bool in your form's scope and use it to negate one of the two events that are fired:

    Private _skipPreviewKeyDown As Boolean = False
Private Sub WebBrowser1_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles WebBrowser1.PreviewKeyDown

    If _skipPreviewKeyDown = True Then
        _skipPreviewKeyDown = False
        Exit Sub
    Else
        _skipPreviewKeyDown = True
    End If

    'Select Case e.KeyDa
    MsgBox(e.KeyValue)

End Sub


Try using KeyUp event instead. I think the key repeat is causing you problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜