7 // --------------------- XBox Input -----------------------------
\r
9 static HANDLE GamePad=NULL;
\r
10 static XINPUT_STATE Pad;
\r
12 static int DeadZone(short *paxis)
\r
17 if (a<-zone) a+=zone;
\r
18 else if (a> zone) a-=zone; else a=0;
\r
24 static int DeviceRead()
\r
28 memset(Inp.axis, 0,sizeof(Inp.axis));
\r
29 memset(Inp.button,0,sizeof(Inp.button));
\r
31 if (GamePad==NULL) GamePad=XInputOpen(XDEVICE_TYPE_GAMEPAD,0,XDEVICE_NO_SLOT,NULL);
\r
32 if (GamePad==NULL) return 1;
\r
34 // Read XBox joypad:
\r
35 XInputGetState(GamePad,&Pad);
\r
38 Inp.axis[0]=Pad.Gamepad.sThumbLX;
\r
39 Inp.axis[1]=Pad.Gamepad.sThumbLY;
\r
40 Inp.axis[2]=Pad.Gamepad.sThumbRX;
\r
41 Inp.axis[3]=Pad.Gamepad.sThumbRY;
\r
43 for (a=0;a<4;a++) DeadZone(Inp.axis+a);
\r
45 // Get digital buttons:
\r
46 but=Pad.Gamepad.wButtons;
\r
49 if (but&(1<<a)) Inp.button[a]=0xff;
\r
52 // Get analog buttons:
\r
53 memcpy(Inp.button+8, Pad.Gamepad.bAnalogButtons, 8);
\r
60 // --------------------- Windows Input -----------------------------
\r
64 static int DeviceRead()
\r
67 int axis[]={0,0,0,0};
\r
70 memset(Inp.axis, 0,sizeof(Inp.axis));
\r
71 memset(Inp.button,0,sizeof(Inp.button));
\r
73 if (GetForegroundWindow()!=FrameWnd) return 1;
\r
75 if (GetAsyncKeyState(VK_LEFT )) axis[0]-=push;
\r
76 if (GetAsyncKeyState(VK_RIGHT)) axis[0]+=push;
\r
77 if (GetAsyncKeyState(VK_DOWN )) axis[1]-=push;
\r
78 if (GetAsyncKeyState(VK_UP )) axis[1]+=push;
\r
79 for (i=0;i<4;i++) Inp.axis[i]=(short)axis[i];
\r
81 if (GetAsyncKeyState(VK_RETURN)) Inp.button[4]=0xff; // Start
\r
82 //if (GetAsyncKeyState(VK_ESCAPE)) Inp.button[7]=0xff; // Right thumb
\r
84 if (GetAsyncKeyState('Z')) Inp.button[10]=0xff;
\r
85 if (GetAsyncKeyState('X')) Inp.button[ 8]=0xff;
\r
86 if (GetAsyncKeyState('C')) Inp.button[ 9]=0xff;
\r
88 if (GetAsyncKeyState('A')) Inp.button[13]=0xff;
\r
89 if (GetAsyncKeyState('S')) Inp.button[12]=0xff;
\r
90 if (GetAsyncKeyState('D')) Inp.button[11]=0xff;
\r
91 if (GetAsyncKeyState('F')) Inp.button[14]=0xff;
\r
93 static int sblobked = 0;
\r
94 if (!sblobked && GetAsyncKeyState(VK_TAB)) {
\r
98 else if (!sblobked && GetAsyncKeyState(VK_ESCAPE))
\r
100 PostMessage(FrameWnd, WM_COMMAND, 0x20000 | 1000, 0);
\r
104 sblobked = GetAsyncKeyState(VK_TAB) | GetAsyncKeyState(VK_ESCAPE);
\r
113 memset(&Inp,0,sizeof(Inp));
\r
115 memset(&Pad,0,sizeof(Pad));
\r
116 XInitDevices(0,NULL);
\r
124 if (GamePad) XInputClose(GamePad);
\r
134 DeviceRead(); // Read XBox or PC device
\r
136 // Use left analog for left digital too:
\r
137 if (Inp.axis[1]>= push) Inp.button[0]|=0xff; // Up
\r
138 if (Inp.axis[1]<=-push) Inp.button[1]|=0xff; // Down
\r
139 if (Inp.axis[0]<=-push) Inp.button[2]|=0xff; // Left
\r
140 if (Inp.axis[0]>= push) Inp.button[3]|=0xff; // Right
\r
142 // Update debounce/time held information:
\r
143 for (i=0;i<sizeof(Inp.held);i++)
\r
145 if (Inp.held[i]==0)
\r
147 if (Inp.button[i]>30) Inp.held[i]=1; // Just pressed
\r
151 // Is the button still being held down?
\r
153 if (Inp.held[i]>=0x80) Inp.held[i]&=0xbf; // (Keep looping around)
\r
155 if (Inp.button[i]<25) Inp.held[i]=0; // No
\r
159 // Work out some key repeat values:
\r
160 for (i=0;i<sizeof(Inp.repeat);i++)
\r
163 int held=Inp.held[i];
\r
165 if (held==1) rep=1;
\r
166 if (held>=0x20 && (held&1)) rep=1;
\r
174 // Set Lightgun calibration values:
\r
175 int InputLightCal(int cx,int cy,int ux,int uy)
\r
178 XINPUT_LIGHTGUN_CALIBRATION_OFFSETS cal;
\r
180 memset(&cal,0,sizeof(cal));
\r
182 cal.wCenterX =(WORD)cx;
\r
183 cal.wCenterY =(WORD)cy;
\r
184 cal.wUpperLeftX=(WORD)ux;
\r
185 cal.wUpperLeftY=(WORD)uy;
\r
186 XInputSetLightgunCalibration(GamePad,&cal);
\r
190 (void)(cx+cy+ux+uy);
\r