开发者

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

开发者 https://www.devze.com 2022-12-28 13:50 出处:网络
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?

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

精彩评论

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