Well, I finally got it. As promised, here is the VB.NET code. Note that I only have one modeless form, not an MDI application, so I did not create the loop to check each mdiChild, but it should not be too dificult to do.
I have the following in the add-in class...
#Region "Functions and Constants for Modeless Form Message Hook"
Public Const PM_NOREMOVE = &H0 Public Const PM_REMOVE = &H1 Public Const WM_NULL = &H0 Public Const WM_KEYFIRST = &H100 Public Const WM_KEYLAST = &H108 Public Const WH_KEYBOARD = &H2 Public Const WH_GETMESSAGE = &H3
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Integer
Public Declare Function UnhookWindowsHookEx Lib "user32" _ (ByVal hHook As Integer) As Integer
Public Declare Function IsWindow Lib "user32" _ (ByVal hWnd As Integer) As Boolean
Public Declare Function IsDialogMessage Lib "user32" _ (ByVal hWnd As Integer, _ ByRef lpMsg As System.Windows.Forms.Message) As Boolean
Public Declare Function CallNextHookEx Lib "user32" _ (ByVal hHook As Integer, _ ByVal nCode As Integer, _ ByVal wParam As Integer, _ ByRef lParam As System.Windows.Forms.Message) As Integer
Public Delegate Function MessageHookDelegate(ByVal code As Integer, _ ByVal wParam As Integer, _ ByRef lParam As System.Windows.Forms.Message) As Integer
_ Private MessageHookCallback As MessageHookDelegate
Public Declare Function SetWindowsHookEx Lib "user32" _ Alias "SetWindowsHookExA" _ (ByVal idHook As Integer, _ ByVal lpfn As MessageHookDelegate, _ ByVal hmod As Integer, _ ByVal dwThreadId As Integer) As Integer
Public m_hook As Integer #End Region
In the ConnectToSW function I have...
'Create MessageHook Delegate Callback MessageHookCallback = New MessageHookDelegate( _ AddressOf MessageHook) 'Put MessageHook function in the Message Hook list m_hook = SetWindowsHookEx(WH_GETMESSAGE, _ MessageHookCallback, 0, GetCurrentThreadId())
In the DisconnectFromSW function I have...
'Pull our function out of the Message Hook list If (m_hook vbNull) Then UnhookWindowsHookEx(m_hook)
Then our MessageHook Function...
Public Function MessageHook(ByVal code As Integer, _ ByVal wParam As Integer, _ ByRef lParam As System.Windows.Forms.Message) As Integer
If code >= 0 And wParam = PM_REMOVE Then 'Don't translate non-input events If (lParam.Msg >= WM_KEYFIRST) And (lParam.Msg