The solution I need is 99% encapsulated in the accepted solution linked below:
How to perform .Onkey Event in an Excel Add-In created with Visual Studio 2010?
However, it does not seem to work for hooking the ALT key. I have looked around and have come across several C# examples but I am new to programming and I am learning VB .NET so with my level of knowledge I have not been able to port the code in other C# examples successfully to make it work in my VB .NET project.
Since the code linked above already does everything I need, I'd like to keep using it, but I would appreciate it if someone could show me how to make it also hook the ALT key. I suppose there is a constant that needs to be passed and checked for in a specific way but I have not been able to figure it out in the last 4 days since finding this solution. Any help will be much appreciated.
Thanks ever so much!
Edit: @Vincent, here is the code I am testing with that breaks with the overflow error:
Imports InputHelperLib
Public Class ThisAddIn
Dim KeyboardHook As InputHelper.Hooks.LocalKeyboardHook
Private Sub ThisAddIn_Startup() Handles Me.Startup
KeyboardHook = New InputHelper.Hooks.LocalKeyboardHook
AddHandler KeyboardHook.KeyDown, AddressOf KeyboardHook_KeyDown
AddHandler KeyboardHook.KeyUp, AddressOf KeyboardHook_KeyUp
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
If KeyboardHook IsNot Nothing Then KeyboardHook.Dispose()
End Sub
Private Sub KeyboardHook_KeyDown(sender As Object, e As InputHelper.Hooks.KeyboardHookEventArgs)
If e.Modifiers = InputHelper.ModifierKeys.Alt AndAlso e.KeyCode = System.Windows.Forms.Keys.M Then
System.Windows.Forms.MessageBox.Show("ALT + M was pressed!")
End If
End Sub
Private Sub KeyboardHook_KeyUp(sender As Object, e As InputHelper.Hooks.KeyboardHookEventArgs)
If e.Modifiers = InputHelper.ModifierKeys.Alt AndAlso e.KeyCode = System.Windows.Forms.Keys.M Then
System.Windows.Forms.MessageBox.Show("ALT + M was released!")
End If
End Sub
End Class