justcoding121 / windows-user-action-hook

A .NET library to subscribe for Windows operating system global user actions such mouse, keyboard, clipboard & print events
MIT License
278 stars 76 forks source link

VB.Net - WM_PASTE #14

Open snrchang opened 6 years ago

snrchang commented 6 years ago

Could you be so kind to give me a example of using your awesome library in VB.Net

Also could this library be used to globally catch the WM_PASTE hook. So you can detect user paste not only by ctrl v but also by context menu

Thanks so much for this library and your work

justcoding121 commented 6 years ago

I am not sure on the syntax for event handling in VB.Net. Its been years.

    Dim eventHookFactory = New EventHookFactory()
    Dim keyboardWatcher = eventHookFactory.GetKeyboardWatcher()
    keyboardWatcher.Start()

I see that difficulty is with attaching the events with handlers. It won't be any different than the vb sample code in msdn for timer elapsed event.

https://msdn.microsoft.com/en-us/library/system.timers.timer.interval(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2

May be something like below.


 ' Hook up the Elapsed event for the timer.  
 AddHandler keyboardWatcher.OnKeyInput, AddressOf OnKeyInputEvent

   Private Sub OnKeyInputEvent(source As Object, e As KeyInputEventArgs)
         Console.WriteLine(string.Format("Key {0} event of key {1}", e.KeyData.EventType, e.KeyData.Keyname));
    End Sub