How to catch Control-V in a C # application?

I tried to override WndProc, but the insert message did not appear.

Then I tried to create my own filter and using the PreFilterMessage method. I was able to catch a message with a value of 257 (KEYUP event), but this is not enough ...

+6
c # message keyevent
source share
2 answers

Using:

protected override void OnKeyDown(KeyEventArgs e) { if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control) { MessageBox.Show("Hello world"); } base.OnKeyDown(e); } 

Make sure your form is KeyPreview = true.

+17
source share

You can do it:

  • Intercepting Ctrl + V in KeyDown (or KeyUp) of your form
  • Create a menu in your form that contains the Paste option, which has the keyboard shortcut Ctrl + V (this might be better, since you will have users looking for options).
  • Intercepting the KEYDOWN message, as you described in the question, and checking whether the key is pressed at this time (I think this is the most difficult of all 3).

Personally, I would like to use the menu option.

+2
source share

All Articles