0

I have a TextBox's KeyDown event that start a timer when it is called. I also have a Paste MenuStripItem and I set the ShorcutKeys property in Design View to Ctrl + V.

I notice that when user press the shortcut keys (Ctrl + V), the KeyDown event will not be called. And when I set the ShortcutKeys property to None, KeyDown is normally called. Is there a way to fire both event when I press the Ctrl + V?

I has tried with other MenuStripItem and the result are the same.

EDIT: Thank you very much, @Hans. When I move my code from KeyDown event to ProcessCmdKey, it works really well. (So I suppose the ProcessCmdKey is the method which is called everytime a key is pressed nomatter what it is). Because you deleted your previous anwser so I can't mark it as answer now.

1 Answer 1

0
private void somethind_KeyDown(object sender, KeyEventArgs e)
{
    if (KeyCodes.Contains(e.KeyValue) || (e.KeyCode==Keys.V && e.Control))
        e.SuppressKeyPress = false;
    else 
        e.SuppressKeyPress=true;
}

See this list of keycodes: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

I hope this helps!

Sign up to request clarification or add additional context in comments.

9 Comments

I mean when you set a shortcut keys to the menustripitem, and you press that shortcut keys, it will ignore the keydown event. I'm not ask about how to catch the Ctrl + V key in the keydown event
Might be because Ctrl+V is well embedded into the system itself.
Nah, It only ignore when you set the MenuStripItem's ShortcutKeys property.
I know that they ignore when you set the MenuStripItem's shortcut key action. However, either this is a new behavior or something has changed, are you on Windows 8.1? In addition, which Visual Studio and C# version do you run?
Yes, I use Windows 8.1, Visual Studio 13.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.