Results 1 to 15 of 15

Thread: KeyDown event

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    KeyDown event

    I have the following code in an attempt to capture the DEL key.

    Code:
    private void desktopThumbs_KeyDown(object sender, KeyEventArgs e)
    {
       if (e.KeyCode == Keys.Delete)
       {
          MessageBox.Show("DELETE HIT - KeyDown");
        }
    }
    I can trap the HOME, PAGEUP and PAGEDOWN keys but the DEL key does nothing.
    However if I hit SHIFT & DEL it does get caught.

    Any Ideas whats happening. I don't understand why I have to hit shift.


    Thanks In Advance

    Parksie

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: KeyDown event

    Hey,

    You have to be careful here, are you hitting the Delete Key, or are you hitting the Backspace key. Both result in different KeyCodes.

    I have used the code that you have posted above, and it works as expected when I hit the Delete key.

    Try just doing:

    Code:
    MessageBox.Show(e.KeyCode);
    In the KeyDown Handler to see what KeyCode is being used.

    Gary

  3. #3

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: KeyDown event

    I followed your advice and tried :
    Code:
    private void desktopThumbs_KeyDown(object sender, KeyEventArgs e)
    {
          MessageBox.Show("DELETE HIT - KeyDown");
    }
    }
    Believe it or not the DEL key does nothing at all. I need to hit the shift key with it.

    Parksie

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: KeyDown event

    That seems very strange!!

    What keyboard layout are you using? I hit the delete key (without the shift key) and it triggers the keydown event, with a KeyCode of 46, as expected.

    Gary

  5. #5

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: KeyDown event

    Dell

    I tried running the code on another machine here at work and it does the same thing.

    Insane

    Parksie

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: KeyDown event

    Hey,

    By keyboard layout, I meant within Windows. i.e. I use English (United Kingdom), but I was wondering if maybe you use a layout such as Dvorak, that alters the keys, in which case the Delete key has a different function.

    Gary

  7. #7

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: KeyDown event

    Nope.

    There's nothing extraordinary with my setup.

    This is NUTS

    Parksie

  8. #8
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: KeyDown event

    Hey,

    Using this code:

    Code:
    private void desktopThumbs_KeyDown(object sender, KeyEventArgs e)
    {
          MessageBox.Show(e.KeyValue.ToString());
    }
    Do you not get a MessageBox with 16 in it when you hit shift? That is what I get.

    I think there is something going on that you are not mentioning.

    What is the exact code you are using?

    Gary

  9. #9
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: KeyDown event

    This works well for me ?

    vb Code:
    1. Private Sub TextBox3_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyDown
    2.         If e.KeyCode = Keys.Delete Then
    3.             MessageBox.Show("delete")
    4.         End If
    5.     End Sub
    Please mark you thread resolved using the Thread Tools as shown

  10. #10
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: KeyDown event

    Yip, that is what works for me as well. I am sure there is something that the OP is not telling us.

    Gary

  11. #11

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: KeyDown event

    When I hit the SHIFT key I get the keyvalue of 16. If while holding that same SHIFT key down I also hit the DELETE key I get the keyvalue 46.

    The problem is that when I hit just the DEL key I get nothing.


    AAAARRRGGGHHHH

    Parksie

  12. #12
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: KeyDown event

    Again, that doesn't make any sense.

    Did you say that you tried this on another machine?

    Can you post all the code that you are using, or is this part of a larger application?

    Gary

  13. #13

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: KeyDown event

    I just created a brand new Windows project, dropped a textbox on it and wired up the KEYDOWN event and it worked fine.

    Something in my massive application must be hogging the DEL key. Now I have to find it.

    Christ :-(

    Parksie

  14. #14

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Resolved Re: KeyDown event

    VICTORY.

    The DEL key was bound to a shortcut menu on my parent form.

    What a funky Munky !!!

    Parksie

  15. #15
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: KeyDown event

    Woo Hoo!!! Glad you got it working.

    Remember to follow the links in my signature to mark the thread as resolved.

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