正在阅读:VC学习:获取游戏手柄的按键输入VC学习:获取游戏手柄的按键输入

2004-03-05 14:49 出处:CSDN 作者:mrh123 责任编辑:linjixiong

  }
  NTSTATUS status = HidP_GetCaps(pHidpPreparsedData,&hidPCaps);
  if (status == HIDP_STATUS_SUCCESS)
  {
  _tprintf("CAP信息如下:\n");
  _tprintf(" InputReportByteLength %d\n", hidPCaps.InputReportByteLength);
  _tprintf(" OutputReportByteLength %d\n", hidPCaps.OutputReportByteLength);
  }
  DWORD nReadBytes = 0;
  BYTE *pInputReport = new BYTE[hidPCaps.InputReportByteLength];
  memset(pInputReport,0,hidPCaps.InputReportByteLength);

  do
  {
  ReadFile(hDeviceHandle,pInputReport,hidPCaps.InputReportByteLength,&nReadBytes,NULL);
  if (hidPCaps.InputReportByteLength == nReadBytes)
  {
  for(unsigned int i=0; i<(nReadBytes-1);i++)
  _tprintf("%02x-",pInputReport[i]);
  _tprintf("%02x\r",pInputReport[nReadBytes-1]);
  }
  if (pInputReport[nReadBytes-2] == 0x20) //break the loop when pressing a specific key
  {
  _tprintf("\n");
  break;
  }
  Sleep(10);
  }while(hidPCaps.InputReportByteLength == nReadBytes);

  //释放句柄资源
  CloseHandle(hDeviceHandle);
  }

  MemberIndex++;
  }while(bSuccess);

  SetupDiDestroyDeviceInfoList(hDevInfo);
  }




察看评论详细内容 我要发表评论
作者笔名简短内容 发表时间
:
键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品