Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Detect input source (keyboard or USB device) on Windows 7 .Net Windows Application

Posted on 2011-09-10
3
Medium Priority
?
2,180 Views
Last Modified: 2013-12-17
I have a .Net 4 Windows Forms project with Visual Studio 2010 using c#.  This is running on Windows 7 x64 laptop.

I need to determine if input has originated from the laptop's keyboard or from barcode scanner attached by USB.  Can I do this?
0
Comment
Question by:canuckconsulting
3 Comments
 
LVL 4

Expert Comment

by:Friman001
ID: 36516684
0
 

Author Comment

by:canuckconsulting
ID: 36516689
I need to know if the input has come from the scanner though as I treat it different to data from keyboard.  Ultimately I want any scanned data to result in a search no matter what screen or control a user is on.
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 36516697
It depends on how your scanner returns the data, but since you seem to have problem identifying between the scanner and the keyboard, the scanner probably returns the data throught the KeyPress event. Isn't it?

If so, I would be surprise that it would also trigger the KeyDow event. You could set a form level boolean variable to True in KeyDown and check for it in the KeyPress. If it is True, that means that the data is coming from the keyboard.

Do not forget to reset it to False at the end of the KeyPress, in order to be able to properly detect the provenance of the next character.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Integration Management Part 2
Screencast - Getting to Know the Pipeline

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question