Appendix:  WithEvents

To handle the events raised by an event source (such as a KeyboardEvents object), declare a variable using the keyword WithEvents.

Private WithEvents objmKeyboardEvents As KeyboardEvents

This will put objmKeyboardEvents in the left drop-down list of your code window, and events raised by objmKeyboardEvents can be selected from the right drop-down list, just like a visual control placed on the form's designer window.

For objmKeyboardEvents to actually raise any events, it must be explicity created at run-time.

Eg:

Private Sub Form_Load()
    'Trap keyboard events from all threads.
    Set objmKeyboardEvents = GetAllThreads.KeyboardEvents
End Sub

Home Copyright and Disclaimer