如何在C ++中获取JoyStick Z旋转消息

我有C ++代码,正确地拦截了我的Saitek Cyborg游戏杆的游戏杆x和y位置。

这个操纵杆也有能力围绕手柄轴线扭转,我正试图得到这个动议的消息。

对于x和y,消息ID是MM_JOY1MOVE和MM_JOY2MOVE,它们允许我捕获该棒的x和y位置。

对于z轴,有MM_JOY1ZMOVE和MM_JOY2ZMOVE,但是这些都没有捕捉到扭转运动。

查看mmsystem.h,find以下定义:

.... #define MM_JOY1MOVE 0x3A0 /* joystick */ #define MM_JOY2MOVE 0x3A1 #define MM_JOY1ZMOVE 0x3A2 #define MM_JOY2ZMOVE 0x3A3 #define MM_JOY1BUTTONDOWN 0x3B5 #define MM_JOY2BUTTONDOWN 0x3B6 #define MM_JOY1BUTTONUP 0x3B7 #define MM_JOY2BUTTONUP 0x3B8 ... 

但是这些都不行。

问题是:z-twist动作的messageID是什么,或者我怎样才能find它?

Solutions Collecting From Web of "如何在C ++中获取JoyStick Z旋转消息"

不知道你的意思是Z扭曲(如果它是模拟轴或只是POV按钮),但我用JOYINFOEXJOYCAPS这样处理游戏杆:

 //--------------------------------------------------------------------------- //--- Spektres Joystick class ver: 1.1 -------------------------------------- //--------------------------------------------------------------------------- #ifndef _joystick_h #define _joystick_h //--------------------------------------------------------------------------- //#include <dinput.h> #include <Mmsystem.h> //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- const int _joystick_max=16; //--------------------------------------------------------------------------- class joystick { public: int _enable_double; int _x,_y,_z,_r,_u,_v,_pov; // status non zero ? double x,y,z,r,u,v,pov; // pos double x0,y0,z0,r0,u0,v0; // min double dx,dy,dz,dr,du,dv; // 2/(max-min) double deadzone; DWORD buttons; JOYINFOEX joy_info; JOYCAPS joy_cp; int joy_list[_joystick_max],joy_num; int joy_id; joystick() { deadzone=0.1; _enable_double=1; joy_id=-1; joy_num=0; init_list(); } joystick(joystick& a) { *this=a; } ~joystick() {} joystick* operator = (const joystick *a) { *this=*a; return this; } //joystick* operator = (const joystick &a) { ...copy... return this; } void init_list(); void refresh(); void refresh_cp(); }; //--------------------------------------------------------------------------- void joystick::init_list() { int i,j; joy_num=0; j=JOYSTICKID1; for (i=0;i<_joystick_max;i++) { joy_info.dwSize = sizeof(JOYINFOEX); joy_info.dwFlags=JOY_RETURNALL; if (joyGetPosEx(i,&joy_info)==JOYERR_NOERROR) { joy_list[joy_num]=i; joy_num++; j++; } } j=0; for (i=0;i<joy_num;i++) if (joy_list[i]==joy_id) { j=1; break; } if (!j) { joy_id=-1; if (joy_num>0) joy_id=joy_list[0]; } refresh(); refresh_cp(); } //--------------------------------------------------------------------------- void joystick::refresh() { if (joy_id==-1) return; joy_info.dwSize = sizeof(JOYINFOEX); joy_info.dwFlags=JOY_RETURNALL; joyGetPosEx(joy_id,&joy_info); if (_enable_double) { x=double(joy_info.dwXpos-x0)*dx-1.0; y=double(joy_info.dwYpos-y0)*dy-1.0; z=double(joy_info.dwZpos-z0)*dz-1.0; r=double(joy_info.dwRpos-r0)*dr-1.0; u=double(joy_info.dwUpos-u0)*du-1.0; v=double(joy_info.dwVpos-v0)*dv-1.0; pov=double(joy_info.dwPOV)*0.01; _x=0; if (x<=-deadzone) { _x=1; x+=deadzone; } if (x>=+deadzone) { _x=1; x-=deadzone; } _y=0; if (y<=-deadzone) { _y=1; y+=deadzone; } if (y>=+deadzone) { _y=1; y-=deadzone; } _z=0; if (z<=-deadzone) { _z=1; z+=deadzone; } if (z>=+deadzone) { _z=1; z-=deadzone; } _r=0; if (r<=-deadzone) { _r=1; r+=deadzone; } if (r>=+deadzone) { _r=1; r-=deadzone; } _u=0; if (u<=-deadzone) { _u=1; u+=deadzone; } if (u>=+deadzone) { _u=1; u-=deadzone; } _v=0; if (v<=-deadzone) { _v=1; v+=deadzone; } if (v>=+deadzone) { _v=1; v-=deadzone; } _pov=1; if (joy_info.dwPOV==65535) _pov=0; buttons=joy_info.dwButtons; } } //--------------------------------------------------------------------------- void joystick::refresh_cp() { if (joy_id==-1) return; joyGetDevCaps(joy_id,&joy_cp,sizeof(JOYCAPS)); double q=2.0+deadzone+deadzone; x0=joy_cp.wXmin; dx=joy_cp.wXmax-x0; if (dx) dx=q/dx; y0=joy_cp.wYmin; dy=joy_cp.wYmax-y0; if (dy) dy=q/dy; z0=joy_cp.wZmin; dz=joy_cp.wZmax-z0; if (dz) dz=q/dz; r0=joy_cp.wRmin; dr=joy_cp.wRmax-r0; if (dr) dr=q/dr; u0=joy_cp.wUmin; du=joy_cp.wUmax-u0; if (du) du=q/du; v0=joy_cp.wVmin; dv=joy_cp.wVmax-v0; if (dv) dv=q/dv; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- #endif //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- 

用法:

 // some (locally) global variable joystick joy; // do this in some timer or whatever joy.refresh(); // this just prints the joystick state on VCL Form->Canvas you can rewrite it to what you want: int x,y,dy; dy=20; x=10; y=10-dy; Canvas->FillRect(TRect(x-20,y,x+200,y+15*dy)); Canvas->TextOutA(x,y+=dy,AnsiString().sprintf("x: %i",joy.joy_info.dwXpos)); Canvas->TextOutA(x,y+=dy,AnsiString().sprintf("y: %i",joy.joy_info.dwYpos)); Canvas->TextOutA(x,y+=dy,AnsiString().sprintf("z: %i",joy.joy_info.dwZpos)); Canvas->TextOutA(x,y+=dy,AnsiString().sprintf("r: %i",joy.joy_info.dwRpos)); Canvas->TextOutA(x,y+=dy,AnsiString().sprintf("u: %i",joy.joy_info.dwUpos)); Canvas->TextOutA(x,y+=dy,AnsiString().sprintf("v: %i",joy.joy_info.dwVpos)); Canvas->TextOutA(x,y+=dy,AnsiString().sprintf("b: %i",joy.joy_info.dwButtons)); Canvas->TextOutA(x,y+=dy,AnsiString().sprintf("z: %i",joy.joy_info.dwPOV)); 

这可以处理6个模拟轴+ POV按钮+所有你想要的按钮…

已经写了它的Win2000的,但仍然在Win7的X64与我的4轴+ POV + 7按钮天才操纵杆:)(必须把它的灰尘已经持有多年的手中)

PS。

这是真的老的源代码,所以我需要添加此bds 2006 C隐藏内存管理器冲突到它只是为了确保。