A System-Wide Example
Allowing a single application to make use of the Windows key is nice, but it would be better if we could add a system-wide Windows key function. Taking the previous example one step further, we could create the hook with a system-wide scope so that no matter which application you were in, you could always press the Windows key along with the “w” key, and Internet Explorer would start. This is similar in concept to Windows’ default behavior of launching Windows Explorer when the user presses the Windows key along with the “e” key.
The UI for this application, which Figure 12-4 illustrates, is very simple. The Hook button simply installs the hook by injecting the C++ DLL containing the filter function into all running processes. Now we can press the Hook button and have Internet Explorer start when we press the Windows key and the “w” key. The Unhook button removes the hook from all running processes.
Figure 12-4. Screenshot of system-wide keyboard hook application
Table 12-2 presents the nondefault properties of the form and its controls.
Table 12-2. Nondefault Properties of the Form and Its Controls
Object Type |
Property Name |
Property Value |
---|---|---|
Form |
Name |
SysForm1 |
Form |
Caption |
“SysKeyHk” |
Form |
BorderStyle |
3-Fixed Dialog |
Form |
Top |
420 |
Form |
Left |
132 |
Form |
Height |
1455 |
Form |
Width |
1695 |
Command Button1 |
Name |
cmdHook |
Command Button1 |
Caption |
“Hook” ... |
Get Subclassing and Hooking with Visual Basic now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.