input_default.cpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. #include "input_default.h"
  2. #include "servers/visual_server.h"
  3. #include "os/os.h"
  4. #include "input_map.h"
  5. void InputDefault::SpeedTrack::update(const Vector2& p_delta_p) {
  6. uint64_t tick = OS::get_singleton()->get_ticks_usec();
  7. uint32_t tdiff = tick-last_tick;
  8. float delta_t = tdiff / 1000000.0;
  9. last_tick=tick;
  10. accum+=p_delta_p;
  11. accum_t+=delta_t;
  12. if (accum_t>max_ref_frame*10)
  13. accum_t=max_ref_frame*10;
  14. while( accum_t>=min_ref_frame ) {
  15. float slice_t = min_ref_frame / accum_t;
  16. Vector2 slice = accum*slice_t;
  17. accum=accum-slice;
  18. accum_t-=min_ref_frame;
  19. speed=(slice/min_ref_frame).linear_interpolate(speed,min_ref_frame/max_ref_frame);
  20. }
  21. }
  22. void InputDefault::SpeedTrack::reset() {
  23. last_tick = OS::get_singleton()->get_ticks_usec();
  24. speed=Vector2();
  25. accum_t=0;
  26. }
  27. InputDefault::SpeedTrack::SpeedTrack() {
  28. min_ref_frame=0.1;
  29. max_ref_frame=0.3;
  30. reset();
  31. }
  32. bool InputDefault::is_key_pressed(int p_scancode) {
  33. _THREAD_SAFE_METHOD_
  34. return keys_pressed.has(p_scancode);
  35. }
  36. bool InputDefault::is_mouse_button_pressed(int p_button) {
  37. _THREAD_SAFE_METHOD_
  38. return (mouse_button_mask&(1<<p_button))!=0;
  39. }
  40. static int _combine_device(int p_value,int p_device) {
  41. return p_value|(p_device<<20);
  42. }
  43. bool InputDefault::is_joy_button_pressed(int p_device, int p_button) {
  44. _THREAD_SAFE_METHOD_
  45. return joy_buttons_pressed.has(_combine_device(p_button,p_device));
  46. }
  47. bool InputDefault::is_action_pressed(const StringName& p_action) {
  48. if (custom_action_press.has(p_action))
  49. return true; //simpler
  50. const List<InputEvent> *alist = InputMap::get_singleton()->get_action_list(p_action);
  51. if (!alist)
  52. return NULL;
  53. for (const List<InputEvent>::Element *E=alist->front();E;E=E->next()) {
  54. int device=E->get().device;
  55. switch(E->get().type) {
  56. case InputEvent::KEY: {
  57. const InputEventKey &iek=E->get().key;
  58. if ((keys_pressed.has(iek.scancode)))
  59. return true;
  60. } break;
  61. case InputEvent::MOUSE_BUTTON: {
  62. const InputEventMouseButton &iemb=E->get().mouse_button;
  63. if(mouse_button_mask&(1<<iemb.button_index))
  64. return true;
  65. } break;
  66. case InputEvent::JOYSTICK_BUTTON: {
  67. const InputEventJoystickButton &iejb=E->get().joy_button;
  68. int c = _combine_device(iejb.button_index,device);
  69. if (joy_buttons_pressed.has(c))
  70. return true;
  71. } break;
  72. }
  73. }
  74. return false;
  75. }
  76. float InputDefault::get_joy_axis(int p_device,int p_axis) {
  77. _THREAD_SAFE_METHOD_
  78. int c = _combine_device(p_axis,p_device);
  79. if (_joy_axis.has(c)) {
  80. return _joy_axis[c];
  81. } else {
  82. return 0;
  83. }
  84. }
  85. String InputDefault::get_joy_name(int p_idx) {
  86. _THREAD_SAFE_METHOD_
  87. return joy_names[p_idx].name;
  88. };
  89. static String _hex_str(uint8_t p_byte) {
  90. static const char* dict = "0123456789abcdef";
  91. char ret[3];
  92. ret[2] = 0;
  93. ret[0] = dict[p_byte>>4];
  94. ret[1] = dict[p_byte & 0xf];
  95. return ret;
  96. };
  97. void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid) {
  98. _THREAD_SAFE_METHOD_
  99. Joystick js;
  100. js.name = p_connected ? p_name : "";
  101. js.uid = p_connected ? p_guid : "";
  102. js.mapping = -1;
  103. js.hat_current = 0;
  104. if (p_connected) {
  105. String uidname = p_guid;
  106. if (p_guid == "") {
  107. int uidlen = MIN(p_name.length(), 16);
  108. for (int i=0; i<uidlen; i++) {
  109. uidname = uidname + _hex_str(p_name[i]);
  110. };
  111. };
  112. js.uid = uidname;
  113. //printf("looking for mappings for guid %ls\n", uidname.c_str());
  114. int mapping = -1;
  115. for (int i=0; i < map_db.size(); i++) {
  116. if (js.uid == map_db[i].uid) {
  117. mapping = i;
  118. //printf("found mapping\n");
  119. };
  120. };
  121. js.mapping = mapping;
  122. };
  123. joy_names[p_idx] = js;
  124. emit_signal("joy_connection_changed", p_idx, p_connected);
  125. };
  126. Vector3 InputDefault::get_accelerometer() {
  127. _THREAD_SAFE_METHOD_
  128. return accelerometer;
  129. }
  130. void InputDefault::parse_input_event(const InputEvent& p_event) {
  131. _THREAD_SAFE_METHOD_
  132. switch(p_event.type) {
  133. case InputEvent::KEY: {
  134. if (p_event.key.echo)
  135. break;
  136. if (p_event.key.scancode==0)
  137. break;
  138. // print_line(p_event);
  139. if (p_event.key.pressed)
  140. keys_pressed.insert(p_event.key.scancode);
  141. else
  142. keys_pressed.erase(p_event.key.scancode);
  143. } break;
  144. case InputEvent::MOUSE_BUTTON: {
  145. if (p_event.mouse_button.doubleclick)
  146. break;
  147. if (p_event.mouse_button.pressed)
  148. mouse_button_mask|=(1<<p_event.mouse_button.button_index);
  149. else
  150. mouse_button_mask&=~(1<<p_event.mouse_button.button_index);
  151. if (main_loop && emulate_touch && p_event.mouse_button.button_index==1) {
  152. InputEventScreenTouch touch_event;
  153. touch_event.index=0;
  154. touch_event.pressed=p_event.mouse_button.pressed;
  155. touch_event.x=p_event.mouse_button.x;
  156. touch_event.y=p_event.mouse_button.y;
  157. InputEvent ev;
  158. ev.type=InputEvent::SCREEN_TOUCH;
  159. ev.screen_touch=touch_event;
  160. main_loop->input_event(ev);
  161. }
  162. } break;
  163. case InputEvent::MOUSE_MOTION: {
  164. if (main_loop && emulate_touch && p_event.mouse_motion.button_mask&1) {
  165. InputEventScreenDrag drag_event;
  166. drag_event.index=0;
  167. drag_event.x=p_event.mouse_motion.x;
  168. drag_event.y=p_event.mouse_motion.y;
  169. drag_event.relative_x=p_event.mouse_motion.relative_x;
  170. drag_event.relative_y=p_event.mouse_motion.relative_y;
  171. drag_event.speed_x=p_event.mouse_motion.speed_x;
  172. drag_event.speed_y=p_event.mouse_motion.speed_y;
  173. InputEvent ev;
  174. ev.type=InputEvent::SCREEN_DRAG;
  175. ev.screen_drag=drag_event;
  176. main_loop->input_event(ev);
  177. }
  178. } break;
  179. case InputEvent::JOYSTICK_BUTTON: {
  180. int c = _combine_device(p_event.joy_button.button_index,p_event.device);
  181. if (p_event.joy_button.pressed)
  182. joy_buttons_pressed.insert(c);
  183. else
  184. joy_buttons_pressed.erase(c);
  185. } break;
  186. case InputEvent::JOYSTICK_MOTION: {
  187. set_joy_axis(p_event.device, p_event.joy_motion.axis, p_event.joy_motion.axis_value);
  188. } break;
  189. }
  190. if (main_loop)
  191. main_loop->input_event(p_event);
  192. }
  193. void InputDefault::set_joy_axis(int p_device,int p_axis,float p_value) {
  194. _THREAD_SAFE_METHOD_
  195. int c = _combine_device(p_axis,p_device);
  196. _joy_axis[c]=p_value;
  197. }
  198. void InputDefault::set_accelerometer(const Vector3& p_accel) {
  199. _THREAD_SAFE_METHOD_
  200. accelerometer=p_accel;
  201. }
  202. void InputDefault::set_main_loop(MainLoop *p_main_loop) {
  203. main_loop=p_main_loop;
  204. }
  205. void InputDefault::set_mouse_pos(const Point2& p_posf) {
  206. mouse_speed_track.update(p_posf-mouse_pos);
  207. mouse_pos=p_posf;
  208. if (custom_cursor.is_valid()) {
  209. VisualServer::get_singleton()->cursor_set_pos(get_mouse_pos());
  210. }
  211. }
  212. Point2 InputDefault::get_mouse_pos() const {
  213. return mouse_pos;
  214. }
  215. Point2 InputDefault::get_mouse_speed() const {
  216. return mouse_speed_track.speed;
  217. }
  218. int InputDefault::get_mouse_button_mask() const {
  219. return OS::get_singleton()->get_mouse_button_state();
  220. }
  221. void InputDefault::warp_mouse_pos(const Vector2& p_to) {
  222. OS::get_singleton()->warp_mouse_pos(p_to);
  223. }
  224. void InputDefault::iteration(float p_step) {
  225. }
  226. void InputDefault::action_press(const StringName& p_action) {
  227. if (custom_action_press.has(p_action)) {
  228. custom_action_press[p_action]++;
  229. } else {
  230. custom_action_press[p_action]=1;
  231. }
  232. }
  233. void InputDefault::action_release(const StringName& p_action){
  234. ERR_FAIL_COND(!custom_action_press.has(p_action));
  235. custom_action_press[p_action]--;
  236. if (custom_action_press[p_action]==0) {
  237. custom_action_press.erase(p_action);
  238. }
  239. }
  240. void InputDefault::set_emulate_touch(bool p_emulate) {
  241. emulate_touch=p_emulate;
  242. }
  243. bool InputDefault::is_emulating_touchscreen() const {
  244. return emulate_touch;
  245. }
  246. void InputDefault::set_custom_mouse_cursor(const RES& p_cursor,const Vector2& p_hotspot) {
  247. if (custom_cursor==p_cursor)
  248. return;
  249. custom_cursor=p_cursor;
  250. if (p_cursor.is_null()) {
  251. set_mouse_mode(MOUSE_MODE_VISIBLE);
  252. VisualServer::get_singleton()->cursor_set_visible(false);
  253. } else {
  254. set_mouse_mode(MOUSE_MODE_HIDDEN);
  255. VisualServer::get_singleton()->cursor_set_visible(true);
  256. VisualServer::get_singleton()->cursor_set_texture(custom_cursor->get_rid(),p_hotspot);
  257. VisualServer::get_singleton()->cursor_set_pos(get_mouse_pos());
  258. }
  259. }
  260. void InputDefault::set_mouse_in_window(bool p_in_window) {
  261. if (custom_cursor.is_valid()) {
  262. if (p_in_window) {
  263. set_mouse_mode(MOUSE_MODE_HIDDEN);
  264. VisualServer::get_singleton()->cursor_set_visible(true);
  265. } else {
  266. set_mouse_mode(MOUSE_MODE_VISIBLE);
  267. VisualServer::get_singleton()->cursor_set_visible(false);
  268. }
  269. }
  270. }
  271. // from github.com/gabomdq/SDL_GameControllerDB
  272. static const char *s_ControllerMappings [] =
  273. {
  274. #ifdef WINDOWS_ENABLED
  275. "8f0e1200000000000000504944564944,Acme,platform:Windows,x:b2,a:b0,b:b1,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b5,rightshoulder:b6,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2,",
  276. "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Windows,",
  277. "ffff0000000000000000504944564944,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,platform:Windows,",
  278. "6d0416c2000000000000504944564944,Generic DirectInput Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Windows,",
  279. "6d0419c2000000000000504944564944,Logitech F710 Gamepad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,platform:Windows,",
  280. "88880803000000000000504944564944,PS3 Controller,a:b2,b:b1,back:b8,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b9,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:b7,rightx:a3,righty:a4,start:b11,x:b0,y:b3,platform:Windows,",
  281. "4c056802000000000000504944564944,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,platform:Windows,",
  282. "25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,back:b9,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a2,righty:a3,start:b8,x:b0,y:b3,platform:Windows,",
  283. "4c05c405000000000000504944564944,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,platform:Windows,",
  284. "6d0418c2000000000000504944564944,Logitech RumblePad 2 USB,platform:Windows,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,",
  285. "36280100000000000000504944564944,OUYA Controller,platform:Windows,a:b0,b:b3,y:b2,x:b1,start:b14,guide:b15,leftstick:b6,rightstick:b7,leftshoulder:b4,rightshoulder:b5,dpup:b8,dpleft:b10,dpdown:b9,dpright:b11,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b12,righttrigger:b13,",
  286. "4f0400b3000000000000504944564944,Thrustmaster Firestorm Dual Power,a:b0,b:b2,y:b3,x:b1,start:b10,guide:b8,back:b9,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b5,righttrigger:b7,platform:Windows,",
  287. "00f00300000000000000504944564944,RetroUSB.com RetroPad,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,platform:Windows,",
  288. "00f0f100000000000000504944564944,RetroUSB.com Super RetroPort,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,platform:Windows,",
  289. "28040140000000000000504944564944,GamePad Pro USB,platform:Windows,a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,lefttrigger:b6,righttrigger:b7,",
  290. "ff113133000000000000504944564944,SVEN X-PAD,platform:Windows,a:b2,b:b3,y:b1,x:b0,start:b5,back:b4,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b8,righttrigger:b9,",
  291. "8f0e0300000000000000504944564944,Piranha xtreme,platform:Windows,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b6,lefttrigger:b4,rightshoulder:b7,righttrigger:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2,",
  292. "8f0e0d31000000000000504944564944,Multilaser JS071 USB,platform:Windows,a:b1,b:b2,y:b3,x:b0,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,",
  293. "10080300000000000000504944564944,PS2 USB,platform:Windows,a:b2,b:b1,y:b0,x:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a4,righty:a2,lefttrigger:b4,righttrigger:b5,",
  294. "79000600000000000000504944564944,G-Shark GS-GP702,a:b2,b:b1,x:b3,y:b0,back:b8,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b6,righttrigger:b7,platform:Windows,",
  295. "4b12014d000000000000504944564944,NYKO AIRFLO,a:b0,b:b1,x:b2,y:b3,back:b8,guide:b10,start:b9,leftstick:a0,rightstick:a2,leftshoulder:a3,rightshoulder:b5,dpup:h0.1,dpdown:h0.0,dpleft:h0.8,dpright:h0.2,leftx:h0.6,lefty:h0.12,rightx:h0.9,righty:h0.4,lefttrigger:b6,righttrigger:b7,platform:Windows,",
  296. "d6206dca000000000000504944564944,PowerA Pro Ex,a:b1,b:b2,x:b0,y:b3,back:b8,guide:b12,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpdown:h0.0,dpleft:h0.8,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Windows,",
  297. "a3060cff000000000000504944564944,Saitek P2500,a:b2,b:b3,y:b1,x:b0,start:b4,guide:b10,back:b5,leftstick:b8,rightstick:b9,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,platform:Windows,",
  298. "8f0e0300000000000000504944564944,Trust GTX 28,a:b2,b:b1,y:b0,x:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Windows,",
  299. "4f0415b3000000000000504944564944,Thrustmaster Dual Analog 3.2,platform:Windows,x:b1,a:b0,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b5,rightshoulder:b6,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,",
  300. "6f0e1e01000000000000504944564944,Rock Candy Gamepad for PS3,platform:Windows,a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,guide:b12,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,",
  301. "83056020000000000000504944564944,iBuffalo USB 2-axis 8-button Gamepad,a:b1,b:b0,y:b2,x:b3,start:b7,back:b6,leftshoulder:b4,rightshoulder:b5,leftx:a0,lefty:a1,platform:Windows,",
  302. "c911f055000000000000504944564944,GAMEPAD,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
  303. "79000600000000000000504944564944,Generic Speedlink,a:b2,b:b1,y:b0,x:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b6,righttrigger:b7,",
  304. "__XINPUT_DEVICE__,XInput Gamepad,a:b12,b:b13,x:b14,y:b15,start:b4,back:b5,leftstick:b6,rightstick:b7,leftshoulder:b8,rightshoulder:b9,dpup:b0,dpdown:b1,dpleft:b2,dpright:b3,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,",
  305. #endif
  306. #ifdef OSX_ENABLED
  307. "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
  308. "6d0400000000000016c2000000000000,Logitech F310 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
  309. "6d0400000000000018c2000000000000,Logitech F510 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
  310. "6d040000000000001fc2000000000000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
  311. "6d0400000000000019c2000000000000,Logitech Wireless Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* This includes F710 in DInput mode and the "Logitech Cordless RumblePad 2", at the very least. */
  312. "4c050000000000006802000000000000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
  313. "4c05000000000000c405000000000000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
  314. "5e040000000000008e02000000000000,X360 Controller,a:b0,b:b1,back:b9,dpdown:b12,dpleft:b13,dpright:b14,dpup:b11,guide:b10,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,start:b8,x:b2,y:b3,",
  315. #endif
  316. #if X11_ENABLED
  317. "0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
  318. "03000000ba2200002010000001010000,Jess Technology USB Game Controller,a:b2,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,righttrigger:b7,rightx:a3,righty:a2,start:b9,x:b3,y:b0,",
  319. "030000006d04000019c2000010010000,Logitech Cordless RumblePad 2,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
  320. "030000006d0400001dc2000014400000,Logitech F310 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
  321. "030000006d0400001ec2000020200000,Logitech F510 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
  322. "030000006d04000019c2000011010000,Logitech F710 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,",
  323. "030000006d0400001fc2000005030000,Logitech F710 Gamepad (XInput),a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
  324. "030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
  325. "030000004c050000c405000011010000,Sony DualShock 4,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:b6,righttrigger:b7,",
  326. "03000000de280000ff11000001000000,Valve Streaming Gamepad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
  327. "030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
  328. "030000005e0400008e02000010010000,X360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
  329. "030000005e0400001907000000010000,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
  330. "03000000100800000100000010010000,Twin USB PS2 Adapter,a:b2,b:b1,y:b0,x:b3,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a2,lefttrigger:b4,righttrigger:b5,",
  331. "03000000a306000023f6000011010000,Saitek Cyborg V.1 Game Pad,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a4,lefttrigger:b6,righttrigger:b7,",
  332. "030000004f04000020b3000010010000,Thrustmaster 2 in 1 DT,a:b0,b:b2,y:b3,x:b1,start:b9,guide:,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b5,righttrigger:b7,",
  333. "030000004f04000023b3000000010000,Thrustmaster Dual Trigger 3-in-1,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a5,",
  334. "030000008f0e00000300000010010000,GreenAsia Inc. USB Joystick,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b6,lefttrigger:b4,rightshoulder:b7,righttrigger:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2,",
  335. "030000008f0e00001200000010010000,GreenAsia Inc. USB Joystick,x:b2,a:b0,b:b1,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b5,rightshoulder:b6,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a2,",
  336. "030000005e0400009102000007010000,X360 Wireless Controller,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:b13,dpleft:b11,dpdown:b14,dpright:b12,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,",
  337. "030000006d04000016c2000010010000,Logitech Logitech Dual Action,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,",
  338. "03000000260900008888000000010000,GameCube {WiseGroup USB box},a:b0,b:b2,y:b3,x:b1,start:b7,leftshoulder:,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,rightstick:,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,",
  339. "030000006d04000011c2000010010000,Logitech WingMan Cordless RumblePad,a:b0,b:b1,y:b4,x:b3,start:b8,guide:b5,back:b2,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:b9,righttrigger:b10,",
  340. "030000006d04000018c2000010010000,Logitech Logitech RumblePad 2 USB,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,",
  341. "05000000d6200000ad0d000001000000,Moga Pro,a:b0,b:b1,y:b3,x:b2,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a5,righttrigger:a4,",
  342. "030000004f04000009d0000000010000,Thrustmaster Run N Drive Wireless PS3,a:b1,b:b2,x:b0,y:b3,start:b9,guide:b12,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,",
  343. "030000004f04000008d0000000010000,Thrustmaster Run N Drive Wireless,a:b1,b:b2,x:b0,y:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a5,lefttrigger:b6,righttrigger:b7,",
  344. "0300000000f000000300000000010000,RetroUSB.com RetroPad,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,",
  345. "0300000000f00000f100000000010000,RetroUSB.com Super RetroPort,a:b1,b:b5,x:b0,y:b4,back:b2,start:b3,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,",
  346. "030000006f0e00001f01000000010000,Generic X-Box pad,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,",
  347. "03000000280400000140000000010000,Gravis GamePad Pro USB ,x:b0,a:b1,b:b2,y:b3,back:b8,start:b9,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftx:a0,lefty:a1,",
  348. "030000005e0400008902000021010000,Microsoft X-Box pad v2 (US),x:b3,a:b0,b:b1,y:b4,back:b6,start:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b5,lefttrigger:a2,rightshoulder:b2,righttrigger:a5,leftstick:b8,rightstick:b9,leftx:a0,lefty:a1,rightx:a3,righty:a4,",
  349. "030000006f0e00001e01000011010000,Rock Candy Gamepad for PS3,a:b1,b:b2,x:b0,y:b3,back:b8,start:b9,guide:b12,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,",
  350. "03000000250900000500000000010000,Sony PS2 pad with SmartJoy adapter,a:b2,b:b1,y:b0,x:b3,start:b8,back:b9,leftstick:b10,rightstick:b11,leftshoulder:b6,rightshoulder:b7,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b4,righttrigger:b5,",
  351. "030000008916000000fd000024010000,Razer Onza Tournament,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:b13,dpleft:b11,dpdown:b14,dpright:b12,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,",
  352. "030000004f04000000b3000010010000,Thrustmaster Firestorm Dual Power,a:b0,b:b2,y:b3,x:b1,start:b10,guide:b8,back:b9,leftstick:b11,rightstick:b12,leftshoulder:b4,rightshoulder:b6,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b5,righttrigger:b7,",
  353. "03000000ad1b000001f5000033050000,Hori Pad EX Turbo 2,a:b0,b:b1,y:b3,x:b2,start:b7,guide:b8,back:b6,leftstick:b9,rightstick:b10,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,",
  354. "050000004c050000c405000000010000,PS4 Controller (Bluetooth),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
  355. "060000004c0500006802000000010000,PS3 Controller (Bluetooth),a:b14,b:b13,y:b12,x:b15,start:b3,guide:b16,back:b0,leftstick:b1,rightstick:b2,leftshoulder:b10,rightshoulder:b11,dpup:b4,dpleft:b7,dpdown:b6,dpright:b5,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b8,righttrigger:b9,",
  356. "03000000790000000600000010010000,DragonRise Inc. Generic USB Joystick,x:b3,a:b2,b:b1,y:b0,back:b8,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a3,righty:a4,",
  357. "03000000666600000488000000010000,Super Joy Box 5 Pro,a:b2,b:b1,x:b3,y:b0,back:b9,start:b8,leftshoulder:b6,rightshoulder:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b4,righttrigger:b5,dpup:b12,dpleft:b15,dpdown:b14,dpright:b13,",
  358. "05000000362800000100000002010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2,",
  359. "05000000362800000100000003010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2,",
  360. "030000008916000001fd000024010000,Razer Onza Classic Edition,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:b11,dpdown:b14,dpright:b12,dpup:b13,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,",
  361. "030000005e040000d102000001010000,Microsoft X-Box One pad,x:b2,a:b0,b:b1,y:b3,back:b6,guide:b8,start:b7,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:a2,rightshoulder:b5,righttrigger:a5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,",
  362. "03000000790000001100000010010000,RetroLink Saturn Classic Controller,platform:Linux,x:b3,a:b0,b:b1,y:b4,back:b5,guide:b2,start:b8,leftshoulder:b6,rightshoulder:b7,leftx:a0,lefty:a1,",
  363. "050000007e0500003003000001000000,Nintendo Wii U Pro Controller,platform:Linux,a:b0,b:b1,x:b3,y:b2,back:b8,start:b9,guide:b10,leftshoulder:b4,rightshoulder:b5,leftstick:b11,rightstick:b12,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,dpup:b13,dpleft:b15,dpdown:b14,dpright:b16,",
  364. "030000005e0400008e02000004010000,Microsoft X-Box 360 pad,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b6,start:b7,guide:b8,leftshoulder:b4,rightshoulder:b5,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a3,righty:a4,lefttrigger:a2,righttrigger:a5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,",
  365. "030000000d0f00002200000011010000,HORI CO.,LTD. REAL ARCADE Pro.V3,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,guide:b12,start:b9,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,",
  366. "030000000d0f00001000000011010000,HORI CO.,LTD. FIGHTING STICK 3,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,guide:b12,start:b9,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,dpup:h0.1,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7",
  367. "03000000f0250000c183000010010000,Goodbetterbest Ltd USB Controller,platform:Linux,x:b0,a:b1,b:b2,y:b3,back:b8,guide:b12,start:b9,dpleft:h0.8,dpdown:h0.0,dpdown:h0.4,dpright:h0.0,dpright:h0.2,dpup:h0.0,dpup:h0.1,leftshoulder:h0.0,leftshoulder:b4,lefttrigger:b6,rightshoulder:b5,righttrigger:b7,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,",
  368. "0000000058626f782047616d65706100,Xbox Gamepad (userspace driver),platform:Linux,a:b0,b:b1,x:b2,y:b3,start:b7,back:b6,guide:b8,dpup:h0.1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,lefttrigger:a5,righttrigger:a4,leftstick:b9,rightstick:b10,leftx:a0,lefty:a1,rightx:a2,righty:a3,",
  369. "03000000ff1100003133000010010000,PC Game Controller,a:b2,b:b1,y:b0,x:b3,start:b9,back:b8,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7,platform:Linux,",
  370. #endif
  371. #if defined(__ANDROID__)
  372. "4e564944494120436f72706f72617469,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,",
  373. #endif
  374. #ifdef JAVASCRIPT_ENABLED
  375. "Default HTML5 Gamepad, Default Mapping,leftx:a0,lefty:a1,dpdown:b13,rightstick:b11,rightshoulder:b5,rightx:a2,start:b9,righty:a3,dpleft:b14,lefttrigger:a6,x:b2,dpup:b12,back:b8,leftstick:b10,leftshoulder:b4,y:b3,a:b0,dpright:b15,righttrigger:a7,b:b1,",
  376. "303534632d303236382d536f6e792050,PS3 Controller USB,leftx:a0,lefty:a1,dpdown:b6,rightstick:b2,rightshoulder:b11,rightx:a2,start:b3,righty:a3,dpleft:b7,lefttrigger:b8,x:b15,dpup:b4,back:b0,leftstick:b1,leftshoulder:b10,y:b12,a:b14,dpright:b5,righttrigger:b9,b:b13,",
  377. "303534632d303563342d536f6e792043,PS4 Controller USB,leftx:a0,lefty:a1,dpdown:a7,rightstick:b11,rightshoulder:b5,rightx:a2,start:b9,righty:a5,dpleft:a6,lefttrigger:a3,x:b0,dpup:a7,back:b8,leftstick:b10,leftshoulder:b4,y:b3,a:b1,dpright:a6,righttrigger:a4,b:b2,",
  378. "303435652d303238652d4d6963726f73,Nacon X360 Clone(XInput),leftx:a0,lefty:a1,dpdown:a7,rightstick:b10,rightshoulder:b5,rightx:a3,start:b7,righty:a4,dpleft:a6,lefttrigger:a2,x:b2,dpup:a7,back:b6,leftstick:b9,leftshoulder:b4,y:b3,a:b0,dpright:a6,righttrigger:a5,b:b1,",
  379. #endif
  380. NULL
  381. };
  382. InputDefault::InputDefault() {
  383. mouse_button_mask=0;
  384. emulate_touch=false;
  385. main_loop=NULL;
  386. hat_map_default[HAT_UP].type = TYPE_BUTTON;
  387. hat_map_default[HAT_UP].index = JOY_DPAD_UP;
  388. hat_map_default[HAT_UP].value = 0;
  389. hat_map_default[HAT_RIGHT].type = TYPE_BUTTON;
  390. hat_map_default[HAT_RIGHT].index = JOY_DPAD_RIGHT;
  391. hat_map_default[HAT_RIGHT].value = 0;
  392. hat_map_default[HAT_DOWN].type = TYPE_BUTTON;
  393. hat_map_default[HAT_DOWN].index = JOY_DPAD_DOWN;
  394. hat_map_default[HAT_DOWN].value = 0;
  395. hat_map_default[HAT_LEFT].type = TYPE_BUTTON;
  396. hat_map_default[HAT_LEFT].index = JOY_DPAD_LEFT;
  397. hat_map_default[HAT_LEFT].value = 0;
  398. String env_mapping = OS::get_singleton()->get_environment("SDL_GAMECONTROLLERCONFIG");
  399. if (env_mapping != "") {
  400. Vector<String> entries = env_mapping.split("\n");
  401. for (int i=0; i < entries.size(); i++) {
  402. if (entries[i] == "")
  403. continue;
  404. parse_mapping(entries[i]);
  405. };
  406. };
  407. int i = 0;
  408. while (s_ControllerMappings[i]) {
  409. parse_mapping(s_ControllerMappings[i++]);
  410. };
  411. }
  412. uint32_t InputDefault::joy_button(uint32_t p_last_id, int p_device, int p_button, bool p_pressed) {
  413. _THREAD_SAFE_METHOD_;
  414. Joystick& joy = joy_names[p_device];
  415. //printf("got button %i, mapping is %i\n", p_button, joy.mapping);
  416. if (joy.last_buttons[p_button] == p_pressed) {
  417. return p_last_id;
  418. //printf("same button value\n");
  419. }
  420. joy.last_buttons[p_button] = p_pressed;
  421. if (joy.mapping == -1) {
  422. return _button_event(p_last_id, p_device, p_button, p_pressed);
  423. };
  424. Map<int,JoyEvent>::Element* el = map_db[joy.mapping].buttons.find(p_button);
  425. if (!el) {
  426. //don't process un-mapped events for now, it could mess things up badly for devices with additional buttons/axis
  427. //return _button_event(p_last_id, p_device, p_button, p_pressed);
  428. return p_last_id;
  429. };
  430. JoyEvent map = el->get();
  431. if (map.type == TYPE_BUTTON) {
  432. //fake additional axis event for triggers
  433. if (map.index == JOY_L2 || map.index == JOY_R2) {
  434. float value = p_pressed ? 1.0f : 0.0f;
  435. int axis = map.index == JOY_L2 ? JOY_ANALOG_L2 : JOY_ANALOG_R2;
  436. p_last_id = _axis_event(p_last_id, p_device, axis, value);
  437. }
  438. return _button_event(p_last_id, p_device, map.index, p_pressed);
  439. };
  440. if (map.type == TYPE_AXIS) {
  441. return _axis_event(p_last_id, p_device, map.index, p_pressed ? 1.0 : 0.0);
  442. };
  443. return p_last_id; // no event?
  444. };
  445. uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, const JoyAxis& p_value) {
  446. _THREAD_SAFE_METHOD_;
  447. Joystick& joy = joy_names[p_device];
  448. if (joy.last_axis[p_axis] == p_value.value) {
  449. return p_last_id;
  450. }
  451. if (p_value.value > joy.last_axis[p_axis]) {
  452. if (p_value.value < joy.last_axis[p_axis] + joy.filter ) {
  453. return p_last_id;
  454. }
  455. }
  456. else if (p_value.value > joy.last_axis[p_axis] - joy.filter) {
  457. return p_last_id;
  458. }
  459. joy.last_axis[p_axis] = p_value.value;
  460. float val = p_value.min == 0 ? -1.0f + 2.0f * p_value.value : p_value.value;
  461. if (joy.mapping == -1) {
  462. return _axis_event(p_last_id, p_device, p_axis, val);
  463. };
  464. Map<int,JoyEvent>::Element* el = map_db[joy.mapping].axis.find(p_axis);
  465. if (!el) {
  466. //return _axis_event(p_last_id, p_device, p_axis, p_value);
  467. return p_last_id;
  468. };
  469. JoyEvent map = el->get();
  470. if (map.type == TYPE_BUTTON) {
  471. //send axis event for triggers
  472. if (map.index == JOY_L2 || map.index == JOY_R2) {
  473. float value = p_value.min == 0 ? p_value.value : 0.5f + p_value.value / 2.0f;
  474. int axis = map.index == JOY_L2 ? JOY_ANALOG_L2 : JOY_ANALOG_R2;
  475. p_last_id = _axis_event(p_last_id, p_device, axis, value);
  476. }
  477. if (map.index == JOY_DPAD_UP || map.index == JOY_DPAD_DOWN) {
  478. bool pressed = p_value.value != 0.0f;
  479. int button = p_value.value < 0 ? JOY_DPAD_UP : JOY_DPAD_DOWN;
  480. if (!pressed) {
  481. if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_UP, p_device))) {
  482. p_last_id = _button_event(p_last_id, p_device, JOY_DPAD_UP, false);
  483. }
  484. if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_DOWN, p_device))) {
  485. p_last_id = _button_event(p_last_id, p_device, JOY_DPAD_DOWN, false);
  486. }
  487. }
  488. if ( pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) {
  489. return p_last_id;
  490. }
  491. return _button_event(p_last_id, p_device, button, true);
  492. }
  493. if (map.index == JOY_DPAD_LEFT || map.index == JOY_DPAD_RIGHT) {
  494. bool pressed = p_value.value != 0.0f;
  495. int button = p_value.value < 0 ? JOY_DPAD_LEFT : JOY_DPAD_RIGHT;
  496. if (!pressed) {
  497. if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_LEFT, p_device))) {
  498. p_last_id = _button_event(p_last_id, p_device, JOY_DPAD_LEFT, false);
  499. }
  500. if (joy_buttons_pressed.has(_combine_device(JOY_DPAD_RIGHT, p_device))) {
  501. p_last_id = _button_event(p_last_id, p_device, JOY_DPAD_RIGHT, false);
  502. }
  503. }
  504. if ( pressed == joy_buttons_pressed.has(_combine_device(button, p_device))) {
  505. return p_last_id;
  506. }
  507. return _button_event(p_last_id, p_device, button, true);
  508. }
  509. float deadzone = p_value.min == 0 ? 0.5f : 0.0f;
  510. bool pressed = p_value.value > deadzone ? true : false;
  511. if (pressed == joy_buttons_pressed.has(_combine_device(map.index,p_device))) {
  512. // button already pressed or released, this is an axis bounce value
  513. return p_last_id;
  514. };
  515. return _button_event(p_last_id, p_device, map.index, pressed);
  516. };
  517. if (map.type == TYPE_AXIS) {
  518. return _axis_event(p_last_id, p_device, map.index, val );
  519. };
  520. //printf("invalid mapping\n");
  521. return p_last_id;
  522. };
  523. uint32_t InputDefault::joy_hat(uint32_t p_last_id, int p_device, int p_val) {
  524. _THREAD_SAFE_METHOD_;
  525. const Joystick& joy = joy_names[p_device];
  526. JoyEvent* map;
  527. if (joy.mapping == -1) {
  528. map = hat_map_default;
  529. } else {
  530. map = map_db[joy.mapping].hat;
  531. };
  532. int cur_val = joy_names[p_device].hat_current;
  533. if ( (p_val & HAT_MASK_UP) != (cur_val & HAT_MASK_UP) ) {
  534. p_last_id = _button_event(p_last_id, p_device, map[HAT_UP].index, p_val & HAT_MASK_UP);
  535. };
  536. if ( (p_val & HAT_MASK_RIGHT) != (cur_val & HAT_MASK_RIGHT) ) {
  537. p_last_id = _button_event(p_last_id, p_device, map[HAT_RIGHT].index, p_val & HAT_MASK_RIGHT);
  538. };
  539. if ( (p_val & HAT_MASK_DOWN) != (cur_val & HAT_MASK_DOWN) ) {
  540. p_last_id = _button_event(p_last_id, p_device, map[HAT_DOWN].index, p_val & HAT_MASK_DOWN);
  541. };
  542. if ( (p_val & HAT_MASK_LEFT) != (cur_val & HAT_MASK_LEFT) ) {
  543. p_last_id = _button_event(p_last_id, p_device, map[HAT_LEFT].index, p_val & HAT_MASK_LEFT);
  544. };
  545. joy_names[p_device].hat_current = p_val;
  546. return p_last_id;
  547. };
  548. uint32_t InputDefault::_button_event(uint32_t p_last_id, int p_device, int p_index, bool p_pressed) {
  549. InputEvent ievent;
  550. ievent.type = InputEvent::JOYSTICK_BUTTON;
  551. ievent.device = p_device;
  552. ievent.ID = ++p_last_id;
  553. ievent.joy_button.button_index = p_index;
  554. ievent.joy_button.pressed = p_pressed;
  555. parse_input_event(ievent);
  556. return p_last_id;
  557. };
  558. uint32_t InputDefault::_axis_event(uint32_t p_last_id, int p_device, int p_axis, float p_value) {
  559. InputEvent ievent;
  560. ievent.type = InputEvent::JOYSTICK_MOTION;
  561. ievent.device = p_device;
  562. ievent.ID = ++p_last_id;
  563. ievent.joy_motion.axis = p_axis;
  564. ievent.joy_motion.axis_value = p_value;
  565. parse_input_event( ievent );
  566. return p_last_id;
  567. };
  568. InputDefault::JoyEvent InputDefault::_find_to_event(String p_to) {
  569. // string names of the SDL buttons in the same order as input_event.h godot buttons
  570. static const char* buttons[] = {"a", "b", "x", "y", "leftshoulder", "rightshoulder", "lefttrigger", "righttrigger", "leftstick", "rightstick", "back", "start", "dpup", "dpdown", "dpleft", "dpright", "guide", NULL };
  571. static const char* axis[] = {"leftx", "lefty", "rightx", "righty", NULL };
  572. JoyEvent ret;
  573. ret.type = -1;
  574. int i=0;
  575. while (buttons[i]) {
  576. if (p_to == buttons[i]) {
  577. //printf("mapping button %s\n", buttons[i]);
  578. ret.type = TYPE_BUTTON;
  579. ret.index = i;
  580. ret.value = 0;
  581. return ret;
  582. };
  583. ++i;
  584. };
  585. i = 0;
  586. while (axis[i]) {
  587. if (p_to == axis[i]) {
  588. ret.type = TYPE_AXIS;
  589. ret.index = i;
  590. ret.value = 0;
  591. return ret;
  592. };
  593. ++i;
  594. };
  595. return ret;
  596. };
  597. void InputDefault::parse_mapping(String p_mapping) {
  598. _THREAD_SAFE_METHOD_;
  599. JoyDeviceMapping mapping;
  600. Vector<String> entry = p_mapping.split(",");
  601. CharString uid;
  602. uid.resize(17);
  603. mapping.uid = entry[0];
  604. int idx = 1;
  605. while (++idx < entry.size()) {
  606. if (entry[idx] == "")
  607. continue;
  608. String from = entry[idx].get_slice(":", 1);
  609. String to = entry[idx].get_slice(":", 0);
  610. JoyEvent to_event = _find_to_event(to);
  611. if (to_event.type == -1)
  612. continue;
  613. String etype = from.substr(0, 1);
  614. if (etype == "a") {
  615. int aid = from.substr(1, from.length()-1).to_int();
  616. mapping.axis[aid] = to_event;
  617. } else if (etype == "b") {
  618. int bid = from.substr(1, from.length()-1).to_int();
  619. mapping.buttons[bid] = to_event;
  620. } else if (etype == "h") {
  621. int hat_value = from.get_slice(".", 1).to_int();
  622. switch (hat_value) {
  623. case 1:
  624. mapping.hat[HAT_UP] = to_event;
  625. break;
  626. case 2:
  627. mapping.hat[HAT_RIGHT] = to_event;
  628. break;
  629. case 4:
  630. mapping.hat[HAT_DOWN] = to_event;
  631. break;
  632. case 8:
  633. mapping.hat[HAT_LEFT] = to_event;
  634. break;
  635. };
  636. };
  637. };
  638. map_db.push_back(mapping);
  639. //printf("added mapping with uuid %ls\n", mapping.uid.c_str());
  640. };
  641. void InputDefault::add_joy_mapping(String p_mapping, bool p_update_existing) {
  642. parse_mapping(p_mapping);
  643. if (p_update_existing) {
  644. Vector<String> entry = p_mapping.split(",");
  645. String uid = entry[0];
  646. for (int i=0; i<joy_names.size(); i++) {
  647. if (uid == joy_names[i].uid) {
  648. joy_names[i].mapping = map_db.size() -1;
  649. }
  650. }
  651. }
  652. }
  653. void InputDefault::remove_joy_mapping(String p_guid) {
  654. for (int i=map_db.size()-1; i >= 0;i--) {
  655. if (p_guid == map_db[i].uid) {
  656. map_db.remove(i);
  657. }
  658. }
  659. for (int i=0; i<joy_names.size(); i++) {
  660. if (joy_names[i].uid == p_guid) {
  661. joy_names[i].mapping = -1;
  662. }
  663. }
  664. }
  665. //Defaults to simple implementation for platforms with a fixed gamepad layout, like consoles.
  666. bool InputDefault::is_joy_known(int p_device) {
  667. return OS::get_singleton()->is_joy_known(p_device);
  668. }
  669. String InputDefault::get_joy_guid(int p_device) const {
  670. return OS::get_singleton()->get_joy_guid(p_device);
  671. }
  672. //platforms that use the remapping system can override and call to these ones
  673. bool InputDefault::is_joy_mapped(int p_device) {
  674. return joy_names[p_device].mapping != -1 ? true : false;
  675. }
  676. String InputDefault::get_joy_guid_remapped(int p_device) const {
  677. return joy_names[p_device].uid;
  678. }