|
-
Mar 19th, 2009, 04:38 AM
#1
Thread Starter
Fanatic Member
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
-
Mar 19th, 2009, 04:49 AM
#2
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
-
Mar 19th, 2009, 04:55 AM
#3
Thread Starter
Fanatic Member
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.
-
Mar 19th, 2009, 04:57 AM
#4
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
-
Mar 19th, 2009, 05:50 AM
#5
Thread Starter
Fanatic Member
Re: KeyDown event
Dell
I tried running the code on another machine here at work and it does the same thing.
Insane
-
Mar 19th, 2009, 06:01 AM
#6
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
-
Mar 19th, 2009, 06:57 AM
#7
Thread Starter
Fanatic Member
Re: KeyDown event
Nope.
There's nothing extraordinary with my setup.
This is NUTS
-
Mar 19th, 2009, 07:01 AM
#8
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
Last edited by gep13; Mar 19th, 2009 at 07:04 AM.
-
Mar 19th, 2009, 07:12 AM
#9
Re: KeyDown event
This works well for me ?
vb Code:
Private Sub TextBox3_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyDown If e.KeyCode = Keys.Delete Then MessageBox.Show("delete") End If End Sub
Please mark you thread resolved using the Thread Tools as shown
-
Mar 19th, 2009, 07:15 AM
#10
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
-
Mar 19th, 2009, 08:55 AM
#11
Thread Starter
Fanatic Member
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
-
Mar 19th, 2009, 08:57 AM
#12
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
-
Mar 19th, 2009, 09:02 AM
#13
Thread Starter
Fanatic Member
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 :-(
-
Mar 19th, 2009, 09:10 AM
#14
Thread Starter
Fanatic Member
Re: KeyDown event
VICTORY.
The DEL key was bound to a shortcut menu on my parent form.
What a funky Munky !!!
-
Mar 19th, 2009, 09:16 AM
#15
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|