How to control devices on USB with keyboard interface.

AID: 5195
  • Status: Published

1230 points

  • Byexpert_tanmay
  • TypeTips/Tricks
  • Posted on2011-04-07 at 18:55:22
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.
Asked On
2011-04-07 at 18:55:22ID5195
Tags

USB

,

control devices on USB

,

MS Development

Topic

Microsoft Development

Views
697

Comments

Author Comment

by: expert_tanmay on 2011-04-10 at 18:59:16ID: 25651

Hi stone5150,
Thanks

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top MS Development Experts

  1. CodeCruiser

    85,630

    Master

    2,000 points yesterday

    Profile
    Rank: Genius
  2. capricorn1

    60,550

    Master

    0 points yesterday

    Profile
    Rank: Savant
  3. mbizup

    39,400

    0 points yesterday

    Profile
    Rank: Genius
  4. TheLearnedOne

    39,070

    0 points yesterday

    Profile
    Rank: Savant
  5. BuggyCoder

    38,700

    0 points yesterday

    Profile
    Rank: Sage
  6. boag2000

    31,514

    0 points yesterday

    Profile
    Rank: Genius
  7. kaufmed

    28,564

    0 points yesterday

    Profile
    Rank: Genius
  8. fyed

    27,468

    1,200 points yesterday

    Profile
    Rank: Genius
  9. lcohan

    27,401

    0 points yesterday

    Profile
    Rank: Genius
  10. imnorie

    26,900

    0 points yesterday

    Profile
    Rank: Genius
  11. ValentinoV

    24,300

    1,800 points yesterday

    Profile
    Rank: Genius
  12. JamesBurger

    23,104

    0 points yesterday

    Profile
    Rank: Sage
  13. anujnb

    22,936

    0 points yesterday

    Profile
    Rank: Wizard
  14. Idle_Mind

    22,810

    0 points yesterday

    Profile
    Rank: Savant
  15. MlandaT

    22,600

    2,100 points yesterday

    Profile
    Rank: Genius
  16. sarabande

    18,900

    3,800 points yesterday

    Profile
    Rank: Sage
  17. nepaluz

    18,775

    0 points yesterday

    Profile
    Rank: Sage
  18. JDettman

    18,268

    0 points yesterday

    Profile
    Rank: Genius
  19. sedgwick

    17,468

    0 points yesterday

    Profile
    Rank: Genius
  20. HainKurt

    17,220

    0 points yesterday

    Profile
    Rank: Genius
  21. jkr

    16,936

    1,000 points yesterday

    Profile
    Rank: Savant
  22. wdosanjos

    16,621

    0 points yesterday

    Profile
    Rank: Genius
  23. dlmille

    16,600

    2,000 points yesterday

    Profile
    Rank: Genius
  24. Orcbighter

    15,590

    0 points yesterday

    Profile
    Rank: Master
  25. Masteraco

    14,600

    0 points yesterday

    Profile
    Rank: Wizard

Hall Of Fame