winzip icon

Low-Level Keyboard Hooks

Submitted on: 1/3/2015 1:31:00 AM
By: RMD Software (from psc cd)  
Level: Advanced
User Rating: By 15 Users
Compatibility: VB.NET
Views: 4667
     This is a .net class library (KeyboardLowLevelHook) to capture low-level keyboard events by placing a low-level system hook. Use this to track when a user presses some key / key combinations (in any program) and react to those events. The way these functionalities are exposed is very similar to the .net keyboard input scheme : the KeyboardLowLevelHook provides two events : KeyDown and KeyUp (same as on Windows Forms) that, upon instantiation of the class, fires whenever any key gets pressed / released. You can also prevent (block) key combinations from reaching other programs by setting e.Handled = True in the KeyDown and KeyUp events (see example). Note : Be careful when a KeyboardLowLevelHook is instantiated when debugging : keyboard input will react very slowly since the “hook callback procedure” cannot be called when the program is paused. Low-level keyboard hooks require at least Windows NT 4.0 SP3 to run. *Vote only if you wish to... Voting is voluntary : users should not be forced to vote. If you don't want to vote, that's OK! Simply don't vote!*

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
// for :Low-Level Keyboard Hooks
Code from the KeyboardLowLevelHook class is heavily based on an article made by “Managing Low-Level Keyboard Hooks in VB .NET” by Paul Kimmel (
Low-level keyboard hooks are very powerful, but they should not be used for bad / illegal activities including, but not limited to, spying, key logging, etc.
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.