5

I need to intercept the Paste operation (Ctrl+V) and modify the ClipBoard content and propagate the operation.

I have a simple Winform application. I am able to register a global hook by

RegisterHotKey(this.Handle, id, (int)KeyModifier.Control, Keys.V.GetHashCode());  

Then I am able to change the Clipboard content by

Clipboard.SetText("some text");

What I need to know is how to propagate the normal Paste operation from this point onward.

For example: If my application is minimized and another application e.g. Notepad is open and is in focus. The user presses the Ctrl+V , or uses the Paste menu, then my interceptor should change the content of clipboard and those should be pasted on notepad.

ResVict
  • 312
  • 2
  • 12
  • Check the accepted answer in [this SO post](http://stackoverflow.com/questions/6838540/c-sharp-detecting-ctrlv-with-registerhotkey-but-not-intercepting-it). Hope this is exactly what you need. – dotNET Oct 22 '14 at 05:18
  • The problem is that, I am dealing with Ctrl + V generated by some third party application, so there is no key_down occuring. I think, I should ask another question, but I need a global event for Paste operation. Just like the ones available for Clipboard copy event. Ctrl + V is something I thought as a starting point to capture this event. The same Paste operation can be invoked from Edit Menu. – ResVict Oct 22 '14 at 05:33
  • What if you change the content of the clipboard before, i.e. when the user presses CTRL-C? In that case you can set up a hook on WM_DRAWCLIPBOARD message to change the clipboard content. – thepirat000 Oct 22 '14 at 06:03
  • @thepirat000 I did not get your point here. The target is to replace the content of Clipboard whenever the paste operation is performed in any third party application. So we need to have an event notifying us that someone is going to use/paste content from Clipboard. I can make changes to clipboard but I am stuck at propagate part. How to continue the paste operation in 3rd party application after I have changed the clipboard. – ResVict Oct 22 '14 at 06:16
  • Oh, I see. The problem is that Paste is not a global event, and intercepting the keyboard shortcut CTRL-V is not enough. – thepirat000 Oct 22 '14 at 06:23
  • @thepirat000 I understand that CTRL-V is not enough, but even that is not working at the moment. – ResVict Oct 22 '14 at 06:44
  • @dotNET I have tried the solution you mentioned, but it did not work on Notepad or Wordpad. – ResVict Oct 22 '14 at 07:19

0 Answers0