0

我需要将键盘事件注入操作系统(Windows)。

总体情况是我需要将 RS232 设备(类似于条形码扫描仪)转换为“usb 键盘模拟设备”。有一个控制 rs232 设备的后台应用程序,一旦它接收到数据,数据应该被转换为键盘事件,以便由活动应用程序接收,即销售点应用程序。

我知道如何使用 Windows 挂钩来捕获事件,但我不确定新事件是否可以排队进入系统以及如何完成。

想法?

4

3 回答 3

1

If I get your question correctly, you may want to have look at SendInput(...) here: http://msdn.microsoft.com/en-us/library/ms646310(v=vs.85).aspx

Since you didnt specify the language, I assumed C.

Eg:

    INPUT inp;

    memset(&inp, 0, sizeof(INPUT));
    inp.type = INPUT_KEYBOARD;
    inp.ki.wVk = VK_ESCAPE;
    SendInput(1, &inp, sizeof(INPUT)); //send keyDown Event
    inp.ki.dwFlags = KEYEVENTF_KEYUP;
    SendInput(1, &inp, sizeof(INPUT)); //send KeyUp Event
于 2011-01-18T08:46:39.940 回答
0

为什么不将串行端口条目捕获为事件并重新发送 SendKeys 类的密钥?驱动程序编写/测试相当复杂(错误的驱动程序可以关闭 BSOD)你打算用什么语言来做?

于 2011-01-18T08:43:35.340 回答
0

You probably should start looking at BlockInput/SendInput.

These came out after I made my app. I use PostMessage to post WM_KEYDOWN/WM_KEYUP messages to the active window. This is effective, but has a variety of issues. (For example, you have to set the keyboard shift state to do capitals. Thunderbird requires you to send backspaces slowly.)

于 2011-01-18T08:51:34.370 回答