2 #include "SDL/SDL_keyboard.h"
11 cout<<
"Joystick:"<<
mIndex-1<<endl;
12 cout<<
"Name:"<<SDL_JoystickName(
mIndex-1)<<endl;
13 cout<<SDL_JoystickNumAxes(
mJoystick)<<
" axes"<<endl;
14 cout<<SDL_JoystickNumButtons(
mJoystick)<<
" buttons"<<endl;
15 cout<<SDL_JoystickNumBalls(
mJoystick)<<
" balls"<<endl;
16 cout<<SDL_JoystickNumHats(
mJoystick)<<
" hats"<<endl;
37 if(SDL_WasInit(SDL_INIT_JOYSTICK))
38 SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
39 if(SDL_InitSubSystem(SDL_INIT_JOYSTICK)<0){
40 cout<<
"Joystick could not be initialized"<<endl;
45 cout<< SDL_JoystickName(i)<<endl;
58 i->
mKeyStates[
event.key.keysym.sym] = make_pair(
true,event.key.keysym.mod);
59 if(i->
triggered(event.key.keysym.sym, DOUBLECLICKTRIGGERTIME))
61 cout<<
"key:"<<
event.key.keysym.sym<<
" down."<<endl;
64 fnc(event.key.keysym.sym, event.key.keysym.mod);
69 i->
mKeyStates[
event.key.keysym.sym] = make_pair(
false,event.key.keysym.mod);;
71 cout<<
"key:"<<
event.key.keysym.sym<<
" up."<<endl;
74 fnc(event.key.keysym.sym, event.key.keysym.mod);
78 case SDL_MOUSEBUTTONDOWN:
81 cout<<
"Mouse Button:"<<(int)event.button.button<<
" pressed."<<endl;
90 Point2D(event.button.x,event.button.y),
98 fnc(event.button.button-1, ms);
102 case SDL_MOUSEBUTTONUP:
105 cout<<
"Mouse Button:"<<(int)event.button.button<<
" released."<<endl;
115 Point2D(event.button.x,event.button.y),
121 fnc(event.button.button-1, ms);
125 case SDL_MOUSEMOTION:
139 case SDL_JOYBUTTONDOWN:
140 cout<<
"Joybutton "<<(int)event.jbutton.button<<
" down"<<endl;
141 i =
inputs[1+event.jbutton.which];
142 name = SDL_JoystickName(event.jbutton.which);
143 if(name.find(
"360")!=string::npos){
149 fnc(event.jbutton.which, (
JoyButton)event.jbutton.button);
152 else if(name ==
"MotioninJoy Virtual Game Controller"){
154 switch(event.jbutton.button){
189 cout<<
"Unexpected value:"<<
event.jaxis.which<<endl;
193 case SDL_JOYBUTTONUP:
194 cout<<
"Joybutton "<<(int)event.jbutton.button<<
" up"<<endl;
195 i =
inputs[1+event.jbutton.which];
196 name = SDL_JoystickName(event.jbutton.which);
197 if(name.find(
"360")!=string::npos){
202 fnc(event.jbutton.which, (
JoyButton)event.jbutton.button);
205 else if(name ==
"MotioninJoy Virtual Game Controller"){
206 switch(event.jbutton.button){
252 cout<<
"Unexpected value:"<<
event.jaxis.which<<endl;
256 case SDL_JOYAXISMOTION:
257 i =
inputs[1+
event.jaxis.which];
258 name = SDL_JoystickName(event.jbutton.which);
259 if ( ( event.jaxis.value < -THRESHHOLD )|| (event.jaxis.value > THRESHHOLD ))
261 cout<<
"axis "<<(int)event.jaxis.axis<<
" triggered"<<endl;
262 cout<<
"value:"<<(
int)
event.jaxis.value<<endl;
264 if(name.find(
"360")!=string::npos){
266 if( event.jaxis.axis == 0)
275 else if( event.jaxis.axis == 1)
284 else if( event.jaxis.axis == 2)
286 if(event.jaxis.value < 0){
289 if(event.jaxis.value >0){
294 fnc(event.jbutton.which, (
JoyStick)event.jaxis.axis,
Point2D(event.jaxis.value, event.jaxis.value));
299 else if( event.jaxis.axis == 3)
308 else if( event.jaxis.axis == 4)
317 else if(name ==
"MotioninJoy Virtual Game Controller"){
319 if( event.jaxis.axis == 0)
324 if( event.jaxis.axis == 1)
329 if( event.jaxis.axis == 2)
331 if(event.jaxis.value < 0)
333 if(event.jaxis.value >0)
337 if( event.jaxis.axis == 5)
342 if( event.jaxis.axis == 3)
352 cout<<
"axis "<<(int)event.jaxis.axis<<endl;
353 cout<<
"value:"<<(
int)
event.jaxis.value<<endl;
354 if(name.find(
"360")!=string::npos){
356 if( event.jaxis.axis == 0)
361 if( event.jaxis.axis == 1)
366 if( event.jaxis.axis == 2)
368 if(event.jaxis.value < 0)
370 if(event.jaxis.value >0)
374 if( event.jaxis.axis == 3)
379 if( event.jaxis.axis == 4)
384 else if(name ==
"MotioninJoy Virtual Game Controller"){
386 if( event.jaxis.axis == 0)
391 if( event.jaxis.axis == 1)
396 if( event.jaxis.axis == 2)
398 if(event.jaxis.value < 0)
400 if(event.jaxis.value >0)
404 if( event.jaxis.axis == 5)
409 if( event.jaxis.axis == 3)
416 case SDL_JOYHATMOTION:
417 cout<<
"hat "<<(int)event.jhat.hat<<
" triggered"<<endl;
418 cout<<
"value:"<<(
int)
event.jhat.value<<endl;
419 i =
inputs[1+
event.jhat.which];
420 name = SDL_JoystickName(event.jhat.which);
421 if(name.find(
"360")!=string::npos){
422 if(event.jhat.value == SDL_HAT_CENTERED){
423 i =
inputs[1+
event.jhat.which];
425 cout<<
"Centered"<<endl;
427 if(event.jhat.value == SDL_HAT_LEFT){
428 i =
inputs[1+
event.jhat.which];
430 cout<<
"JoyLeft"<<endl;
432 if(event.jhat.value == SDL_HAT_RIGHT){
433 i =
inputs[1+
event.jhat.which];
434 cout<<
"JoyRight"<<endl;
437 if(event.jhat.value == SDL_HAT_UP){
438 i =
inputs[1+
event.jhat.which];
442 if(event.jhat.value == SDL_HAT_DOWN){
443 i =
inputs[1+
event.jhat.which];
447 if(event.jhat.value == SDL_HAT_RIGHTUP){
448 i =
inputs[1+
event.jhat.which];
449 cout<<
"RightUp"<<endl;
453 if(event.jhat.value == SDL_HAT_RIGHTDOWN){
454 i =
inputs[1+
event.jhat.which];
455 cout<<
"RightDown"<<endl;
459 if(event.jhat.value == SDL_HAT_LEFTUP){
460 i =
inputs[1+
event.jhat.which];
461 cout<<
"LeftUp"<<endl;
465 if(event.jhat.value == SDL_HAT_LEFTDOWN){
466 i =
inputs[1+
event.jhat.which];
467 cout<<
"LeftDown"<<endl;
472 else if(name ==
"MotioninJoy Virtual Game Controller"){
473 if(event.jhat.value == SDL_HAT_CENTERED){
479 cout<<
"LeftUp"<<endl;
486 cout<<
"RightDown"<<endl;
492 cout<<
"Centered"<<endl;
495 if(event.jhat.value == SDL_HAT_LEFT){
496 i =
inputs[1+
event.jhat.which];
498 cout<<
"JoyRight"<<endl;
500 if(event.jhat.value == SDL_HAT_RIGHT){
501 i =
inputs[1+
event.jhat.which];
505 if(event.jhat.value == SDL_HAT_UP){
506 i =
inputs[1+
event.jhat.which];
510 if(event.jhat.value == SDL_HAT_DOWN){
511 i =
inputs[1+
event.jhat.which];
512 cout<<
"JoyLeft"<<endl;
515 if(event.jhat.value == SDL_HAT_RIGHTUP){
516 i =
inputs[1+
event.jhat.which];
517 cout<<
"RightUp"<<endl;
521 if(event.jhat.value == SDL_HAT_RIGHTDOWN){
522 i =
inputs[1+
event.jhat.which];
523 cout<<
"LeftDown"<<endl;
527 if(event.jhat.value == SDL_HAT_LEFTUP){
529 i =
inputs[1+
event.jhat.which];
534 if(event.jhat.value == SDL_HAT_LEFTDOWN){
536 i =
inputs[1+
event.jhat.which];
537 cout<<
"wat wat"<<endl;
544 fnc(event.jhat.which,
DPad,
inputs[1+event.jhat.which]->mJoyDPos);
547 case SDL_JOYBALLMOTION:
548 i =
inputs[1+
event.jhat.which];
549 name = SDL_JoystickName(event.jbutton.which);
550 cout<<
"ball "<<(int)event.jball.ball<<
" triggered"<<endl;
551 cout<<
"value:("<<(
int)
event.jball.xrel<<(int)event.jball.yrel<<
')'<<endl;
567 return SDL_NumJoysticks();
651 for(
unsigned int i=1, end =
inputs.size(); i < end; ++i){
660 for(
unsigned int i=1, end =
inputs.size(); i < end; ++i){
670 for(
int i=1,end=
inputs.size(); i<end;++i){
671 dir+=
inputs[i]->getJoyMovement(s);
683 return p.first && (p.second&0xFFF)==mod;
689 return val<=0?
false: SDL_GetTicks() - (ms==-1?TRIGGERTIME:ms) <= val && !
doubleTapped(key, ms);
695 return val<=0?
false: SDL_GetTicks() - (ms==-1?DOUBLECLICKTRIGGERTIME:ms) <= val;
708 return val<=0?
false: SDL_GetTicks() - (ms==-1?TRIGGERTIME:ms) <= val && !
doubleTapped(button, ms);
714 return val<=0?
false: SDL_GetTicks() - (ms==-1?DOUBLECLICKTRIGGERTIME:ms) <= val;
719 unsigned int index = (int)b + button;
722 return inputs[0]->mMouseButtonStates[
index].pressed;
727 unsigned int index = (int)b + button;
731 return m.
time<=0?
false: SDL_GetTicks() - (ms==-1?TRIGGERTIME:ms) <= m.
time && !
doubleTapped(b, button, ms);
736 unsigned int index = (int)b + button;
740 return m.
time<=0?
false: SDL_GetTicks() - (ms==-1?DOUBLECLICKTRIGGERTIME:ms) <= m.
time ;