1
votes

Our application is implemented in WPF using MVVM Light.

We are replacing our old magnetic card reader which is currently a serial one with a USB HID-KB. Serial card reader were easy since we had serial port events to trigger the incoming messages, we had no problem in handling these. But with USB card reader, the events are that of a normal keyboard. By the way, the card reader does not have vendor specific API, this a generic USB device.

As of now the solution is to capture a keydownevent in the view and handle the business logic on the viewmodel.

But the problem here is that the end user can swipe the card irrespective on whatever page he/she is on. We should be able to capture that swipe event. The only option I currently have is that I need to wire this keydownevent on every view as mentioned above.

Is there any way in MVVMLight or WPF that can declare an event on the global level, that can be triggered from every view.

Any pointers will be highly appreciated.

Thanks,

1

1 Answers

1
votes

The solution is very simple. Why don’t you handle the event in a common file, like the base file. Normally we handle application close events in such base files which will always be active. The thing is I have some conditions to check while the application is closing. So I handle the event in the common base file and do the condition checking there.

Please try that and let me know the result..