Implementing Keyboard Hook in VB.NET
Posted on 2013-09-01
I have a VB.NET program that I need to execute code if a key combination is pressed (Ctrl+Shift+Alt+S). This code needs to be executed whether the program is in focus or not.
[Note: If anyone has used Deep Freeze, this is just exactly how that program functions - i.e. after you press a specific key combination the program's menu appears even if the program was not in focus]
In the course of my search for a solution I came across Windows Keyboard Hooks as the most likely candidate. My issue is that I can't get anything I try to work and I just really need help implementing this solution: what code should I use, advice about where to implement it in my program, etc.
So, Specifically, I have created a "Settings Page" in my program that, among other things, has a Checkbox for executing a forced shutdown command if Ctrl+Shift+Alt+S is pressed. [Note: The settings on the Form are saved in a Txt file and loaded both on Form Load and when the "Ok" or "Apply" buttons are pressed on that Settings Page.] I'd like the Ctrl+Alt+Shift+S key combination to become active only when the Checkbox for the feature is marked, and will initiate the forced shutdown regardless of whether my program is in focus or not.
Thank you in advance