我目前正在编写一些 C++ 代码来检测游戏手柄按钮按下。我正在使用以下代码来定义一组可能的按钮按下:
#include <windows.h>
#include <mmsystem.h>
this->buttons[0] = JOY_BUTTON1;
this->buttons[1] = JOY_BUTTON2;
...
this->buttons[31] = JOY_BUTTON32;
然后使用类似下面的东西来检测按下了哪个按钮:
joyGetPosEx(this->joyStickId, &info);
buttonPressed = false;
for(int i=0; i<32; i++){
if((info.dwButtons & this->buttons[i]) == this->buttons[i]){
buttonPressed = true;
cout << "button number " << (i+1) << "was pressed!" << endl;
}
}
if(buttonPressed === false){
cout << "could not detect button press, dwButtons was set to: " << info.dwButtons << endl;
}
这适用于游戏手柄按钮 1-4。但是,按钮 5-32 不起作用。例如,当按下游戏手柄上的按钮 5 时,程序认为dwButtons
设置为 16。JOY_BUTTON5
定义mmsystem.h
为 257。所以在我看来, JOY_BUTTON5 - 32 在 mmsystem 中定义不正确。是这样吗,还是我错过了什么?