Monitor Paste events from the Clipboard

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

I've been able to monitor copy/cut events using PInvoke and User32
SetClipboardViewer, but I need to capture Paste events as well.

If anyone has a way of doing this, please let me know.

Regards,
Jim.
 
You can capture the WM_PASTE message ie.

Private Const WM_PASTE = &H302

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_PASTE Then
Dim txt As String =
Clipboard.GetDataObject().GetData(GetType(String))
End If
MyBase.WndProc(m)
End Sub
 
Cathal said:
You can capture the WM_PASTE message ie.

Private Const WM_PASTE = &H302

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_PASTE Then
Dim txt As String =
Clipboard.GetDataObject().GetData(GetType(String))
End If
MyBase.WndProc(m)
End Sub

Overriding WndProc will only work for controls in the samme process as
my application. I need to be notified when other windows applications
paste the contents of the clipboard.

A global windows hook should allow me to catch WM_PASTE messages for any
active application, but I'm hoping there is a simpler and more elegant
solution.
 
Back
Top