none
multi key pressed RRS feed

  • Question

  • hi there,

    i want to detect a key combinaton at a textbox.
    i have managed to do that on keypressed but if the combination has more than 4 keys then
    some of these are not detected. any ideas? thanks
    • Moved by Linda Liu Friday, March 19, 2010 8:23 AM (From:Windows Presentation Foundation (WPF))
    Sunday, March 14, 2010 11:20 AM

All replies

  • Hi Reven,

    wow, more than 4 keys - at once? Or is it that you're using a timer to allow for a series of keys to be entered, i.e. like VisualStudio does (Ctrl+^+E, for instance)? Also, are you doing this in PreviewKeyDown? It'd probably help if you posted the code you got.
    Cheers,
    Olaf
    http://blogs.intuidev.com
    Sunday, March 14, 2010 1:10 PM
  • hi olaf,

    i need a combination of 1 to 6 keys simultaneously.
    thing something like a piano.

    i have manage to do that up to 4 and sometimes to 5 keys with a timer.
    Up to 4 keys works fine but for more than 4 not.

    this is my code:
    Private Sub textBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
             Handles TextBox1.KeyDown
            ' Initialize the flag to false.
            nonCorrectEntered = True
    
            If e.KeyCode = Keys.F Or _
                e.KeyCode = Keys.D Or _
                e.KeyCode = Keys.S Or _
                e.KeyCode = Keys.J Or _
                e.KeyCode = Keys.J Or _
                e.KeyCode = Keys.K Or _
                e.KeyCode = Keys.L Then
                If e.KeyCode = Keys.F Then
                    F_flag = True
                ElseIf e.KeyCode = Keys.D Then
                    D_flag = True
                ElseIf e.KeyCode = Keys.S Then
                    S_flag = True
                ElseIf e.KeyCode = Keys.J Then
                    J_flag = True
                ElseIf e.KeyCode = Keys.K Then
                    K_flag = True
                ElseIf e.KeyCode = Keys.L Then
                    L_flag = True
                End If
                If timerStart = False Then
                    timeCounter = 0
                    timerStart = True
                    Timer1.Enabled = True
                End If
            End If
    End Sub 
    
        Private Sub textBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) _
            Handles TextBox1.KeyPress
    
            If nonCorrectEntered = True Then
                e.Handled = True
            End If
        End Sub 
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            timeCounter += 1
            If timeCounter >= 2 Then
                timerStart = False
                timeCounter = 0
    
    ' do thing here...
    
         Timer1.Enabled = False
                F_flag = False
                D_flag = False
                S_flag = False
                J_flag = False
                K_flag = False
                L_flag = False
            End If
        End Sub


    any ideas?

    thanks
    Wednesday, March 17, 2010 6:22 AM
  • Hi Reven,

    as for the general concept, would it be possible that it's simply your timer that calls the tick-handler to frequently? Have you tried enlarging the interval? Also, why do you also react to KeyPress - try removing that, moving the e.Handled into KeyDown (or KeyUp)?
    I haven't ever had the requirement to track key-combinations of as much as 6 simultaneous keys, so there actually might really be a limit to the number being tracked, but I'm afraid I don't know ...

    BTW - you've posted your query to the WPF Forum, hence you won't have all too much of a chance to receive answers for WinForms-related questions. I'd suggest you post your questions to the VB Forum instead.
    Cheers,
    Olaf
    http://blogs.intuidev.com
    Wednesday, March 17, 2010 6:39 AM
  • thanks for your time mate,

    i will do so...
    Wednesday, March 17, 2010 10:07 AM