• 5957阅读
  • 2回复

条码枪数据读取:Qt 处理windows 消息,过滤底层 RawInputData 问题? [复制链接]

上一主题 下一主题
离线coffeelzp
 

只看楼主 倒序阅读 楼主  发表于: 2013-04-04
条码枪通常是模拟键盘设备,只要有光标的地方,就会输入,我想读取条码枪数据,并且截获不让它显示文本控件中。现在数据已经拿到,但是无法截取,不知道是不是Qt的bug。


  1. bool Application::winEventFilter(MSG *msg, long *result)
  2. {
  3.     LPARAM lParam = msg->lParam;
  4.     LPBYTE lpb;
  5.     UINT dwSize;
  6.     RAWINPUT *raw;
  7.     if (msg->message == WM_INPUT) {
  8.         GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER));
  9.         lpb = new BYTE[dwSize];
  10.         if (lpb == NULL)
  11.             return 0;
  12.         if (GetRawInputData((HRAWINPUT)lParam,
  13.                             RID_INPUT,
  14.                             lpb,
  15.                             &dwSize,
  16.                             sizeof(RAWINPUTHEADER)) != dwSize)
  17.         {
  18.             qDebug() << "GetRawInputData doesn't return correct siz";
  19.             //OutputDebugStr(TEXT("GetRawInputData doesn't return correct size\n"));
  20.         }
  21.         raw = (RAWINPUT*) lpb;
  22.         if (Application::m_deviceId == raw->header.hDevice) {
  23.             if (raw->header.dwType == RIM_TYPEKEYBOARD) {
  24.                 if (raw->data.keyboard.Message == WM_KEYDOWN ||
  25.                         raw->data.keyboard.Message == WM_SYSKEYDOWN)
  26.                 {
  27.                     USHORT usKey;
  28.                     usKey = raw->data.keyboard.VKey;
  29.                     qDebug() << usKey;
  30. //                    qDebug() << "hDevice" << raw->header.hDevice;
  31.                 }
  32.             }
  33.             result = 0;
  34.             msg = 0;
  35.             return true;
  36.         }
  37.         qDebug() << "id" << raw->header.dwType << raw->data.keyboard.VKey;
  38.         delete[] lpb;
  39.     }
  40.     return QApplication::winEventFilter(msg,result);
  41. }


Qt文档描述,只要 return true,就可以过滤掉消息。  不知道为什么,文本控件上还是会显示。
The message procedure calls this function for every message received. Reimplement this function if you want to process window messages msg that are not processed by Qt. If you don't want the event to be processed by Qt, then return true and set result to the value that the window procedure should return. Otherwise return false.


离线realfan

只看该作者 1楼 发表于: 2013-04-04
条码枪等同于按键,我觉得应该用eventFilter拦截QEvent::KeyPress
例如:
bool XXXX::eventFilter(QObject *obj, QEvent *event)
{
    if(QEvent::KeyPress == event->type())
    {
       。。。。。。。。
        return true;
    }
离线coffeelzp

只看该作者 2楼 发表于: 2013-04-05
这只是拦截了本窗口的按键。 我现在的办法是配合钩子受用。
快速回复
限100 字节
 
上一个 下一个