VB6-从ActiveX DLL中的键盘读取 [英] VB6 - reading from keyboard in an ActiveX DLL

查看:122
本文介绍了VB6-从ActiveX DLL中的键盘读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ActiveX DLL,该DLL当前正在从串行端口读取.现在,我希望它接受来自USB设备的输入.

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

USB设备用作标准的人机接口设备.也就是说,如果我打开记事本,则设备的输出将显示在记事本中,就像在键盘上键入一样.

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.

通常,我会捕获Key Up/Down事件,但是我认为我需要一个窗体,而我的DLL没有窗体.

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.

如何捕获该输入?

[更新]我发现了这个

[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.

嗯, http://www.xtremevbtalk.com/showthread.php?t= 77216 说:您不能在VB中实现全局WH_KEYBOARD挂钩-它需要一个标准(非ActiveX dll),因为必须将其加载到所有正在运行的应用程序的地址空间中."

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."

[上一个日期]因此,也许我可以将一个表单设为1x1像素且不可见,并具有一个GetTheData函数,该函数以模态形式显示表单并收集并返回数据-在表单级别获取键盘输入或(n不可见)控件,然后关闭返回输入的表单.

[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.

那行得通吗?如果有人发布了一个有效的示例,我将给予赏金(我希望该窗体在任务栏上不可见并且没有关闭按钮;用户不应该意识到或能够关闭它,它应该自行关闭)当它从USB连接的HDI接收到足够的输入时.

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).

推荐答案

您可以使用RegisterRawInputDevices监视HID设备的输入,但这需要一个窗口来监听WM_INPUT消息,这意味着对该窗口进行子类化.

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.

这是一个工作示例项目: UsbBarcodeSanner.zip

Here is a working sample project: UsbBarcodeSanner.zip

这篇关于VB6-从ActiveX DLL中的键盘读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆