To recap on my last blog post, I was assigned a task to connect a Barcode Scanner to Dynamics CRM. One of our customers required this integration to check, monitor and manage attendance levels for events.
My previous post was my first attempt at this integration, offering a solution for using barcode scanner as a virtual keyboard. For this solution you just had to split input from the ‘correct’ keyboard and block it. This approach works well but only within its own application. This is good if you work at point of sale and have just the one application open all the time. The downside of this solution was if you run several applications concurrently and the recipient application is not active the output will be redirected to active window. The text will be injected into your document or web form and you’ll have to delete it which is not convenient.
To solve this problem I decided to look for ways to block the input system-wide. This is well-known task which has many solutions (including .net) which are easy to find. After I did some research I found that this (http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx?msg=3290217) article is a pretty nice example how to hook and block KEYPRESS (or MOUSEMOVE) message. But the hook method operates this structure to gain information about the key press
public struct keyboardHookStruct {
public int vkCode;
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
}
As you can see there’s no parameter which could carry information about the exact device which has generated the event. dwExtraInfo looks promising but it has no information about the device either. I’ve spent some more time and had no luck on finding device information – you can do global hook but for all devices or local hook but for exact device but both of them are not good solutions. Also I had few crazy ideas like concurrent threads with both approaches for controlling the input or to measure time between key hits and track them as a barcode if they are too quick. But those ideas were not stable and can’t be used in real life, so I moved forward.
See my next post for my third and final attempt at this Barcode Scanner and Dynamics CRM integration.