Question

I have an ActiveX DLL which currently reads from a serial port. Now I want it to accept input from a USB device.

The USB device functions as a standard Human Interface Device. That is to say, if I open Notepad then the device's output will appear in Notepad as if it were typed on a keyboard.

Normally, I would capture Key Up/Down events, but I think that I need a form for that and my DLL does not have a form.

How can I capture that input?


[Update] I found this http://us.generation-nt.com/answer/anyone-know-how-read-keyboard-input-within-an-activex-dll-help-7934442.html# which claims to do it, but the code there won't work as is uses the AddressOf operator, which can only be used in a .BAS file, so not in an DLL .CLS

I am not even sure if I am looking for a system wide hook or application specific.

Hmmm, http://www.xtremevbtalk.com/showthread.php?t=77216 says "You can't implement a global WH_KEYBOARD hook in VB - it requires a standard (non ActiveX dll) as it has to be loaded into the address space of all the running applications."


[Upper date] So, maybe I can a form, make it 1x1 pixel and invisible and have a function GetTheData which shows the form modally and collects and returns the data - either getting keyboard input at form level or into a (n invisible) control then closes the form returning the input.

Would that work? If anyone posts a working example I will award a bounty (I would prefer that the form not be visible on the task bar and have no close button; the user should not be aware of it, or able to close it, it should close itself when it receives enough input from the USB attached HDI).

Was it helpful?

Solution

You can use RegisterRawInputDevices to monitor HID devices' input but this requires a window to listen for WM_INPUT message which means subclassing the window.

Here is a working sample project: UsbBarcodeSanner.zip

OTHER TIPS

I think you have better option,

using uesr32.dll you can do this task easily,

refer this link

you will be able to use this function

Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer

This dll handles anything you want for user in windows.. refer Old Post

I hope this will help..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top