How to catch Control-V in C# app?

Goran picture Goran · Oct 6, 2008 · Viewed 16.9k times · Source

I've tried to override WndProc, but no message show up on paste event.

Then I tried to create custom filter and using method PreFilterMessage I was able to catch message with value 257 (KEYUP event), but that's not enough...

Answer

Goran picture Goran · Oct 6, 2008

Use:

 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 KeyPreview = true.