Results 1 to 3 of 3

Thread: KeyDown event has changed it's behaviour

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    5

    KeyDown event has changed it's behaviour

    The code below captures a 'Ctrl-A' KeyDown event. Yesterday it worked fine. I've made no changes to it, yet today, it no longer works. The KeyDown event fires, but whereas yesterday, 65 (for 'a') was written to output, now it writes 17 for the control key, even though I'm pressing Ctrl+A. I thought it had something to do with accidentally changing something in the designer details for the form via Find and Replace (not sure how I managed to do that). However, I've rebuilt the form from scratch and it still doesn't work.

    Private Sub ListView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListView.KeyDown

    If e.Control Then
    Console.WriteLine(e.KeyCode)
    If e.KeyCode = Keys.A Then
    For i As Integer = 1 To ListView.Items.Count
    ListView.Items(i - 1).Selected = True
    Next
    End If
    End If

    End Sub


    Can anybody suggest anything? Thanks in advance.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: KeyDown event has changed it's behaviour

    If I do that I get a 17 when I depress the Ctrl key and then a 65 when I depress the A key, which is pretty much what you'd expect.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    5

    Re: KeyDown event has changed it's behaviour

    If I press Ctrl, I get 17. If, while holding down Ctrl, I press A, I still get 17. For several days in a row, it used to output 65 when I held down Ctrl+A and therefore execute the code inside the If e.KeyCode = Keys.A Then statement. I swear it did. There are ample code samples out there that use the same structure and in fact, I got it from surfing the web. It worked fine for a week and then died. Has anybody had a similar problem or could anybody even hazard a guess as to what might cause this change in behaviour? I know I did something to my project that broke it, but I can't figure out what. All I know is, I didn't change this bit of code and I don't know where else to look.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width