<

How to control devices on USB with keyboard interface.

Published on
9,918 Points
3,918 Views
Last Modified:
Approved
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR\Start" from 3 to 4. This procedure is also used by many system admins to disable USB ports within their purview to prevent corporate employees from coping sensitive corporate data. However keyboard interface devices cannot be disabled. The only way to disable them is through BIOS.

There are many devices like Barcode scanner, Magnetic card readers etc. which use the USB port to send data to the computer. Since these devices use the keyboard interface (act like a keyboard), it is by design that MS windows will not allow them to be disabled. However it sometimes is very crucial for an application developer to control these devices. Thus disabling the USB port from BIOS is not at all an agreeable solution. Windows uses messaging system to send events to applications. Messages like key down, key up etc are send by windows to the active window's application. If the application which is intended to receive data is not the active window, data from these kind of devices will fail to reach the application. Thus the application will fail to behave as intended.

The solution to the problem is to write a global keyboard hook. With a global keyboard hook immaterial of the application having the active window the keys or the data is first received by the hook. The hook has the ability either to let the data proceed to the active window's application or redirect to our own application. We now check the time difference between each WM_KEYDOWN message. When the time difference is very small say 30ms, credibility is that the operation is carried out by a device. If the time difference is high it is certainly from the keyboard. With this kind of approach our application can have full control over the USB device.
0
Enjoy this complimentary article view.

Get unlimited access to our entire library of technical procedures, guides, and tutorials written by certified industry professionals.

Get 7 days free
Click here to view the full article

Using this article for work? Experts Exchange can benefit your whole team.

Learn More
COLLABORATE WITH CERTIFIED PROFESSIONALS
Experts Exchange is a tech solutions provider where users receive personalized tech help from vetted certified professionals. These industry professionals also write and publish relevant articles on our site.
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Learn from the best.