@@ -235,8 +235,49 @@ def translate_dict(old_mapping_dict, lookup_dict):
235
235
lookup_result = lookup_dict .get (key )
236
236
if lookup_result is not None :
237
237
translated_map_dict [lookup_result ] = old_mapping_dict [key ]
238
+ del translated_map_dict [key ]
238
239
return translated_map_dict
239
240
241
+ XBOX_DEFAULT_KB_MOUSE_MAPPING = {
242
+ 'XB1_A' : {'code' : 'BTN_LEFT' },
243
+ 'XB1_B' : {'code' : 'BTN_RIGHT' },
244
+ 'XB1_LSX' : {'code' : 'REL_X' },
245
+ 'XB1_LSY' : {'code' : 'REL_Y' },
246
+ 'XB1_LB' : {'code' : 'BTN_LEFT' },
247
+ 'XB1_RB' : {'code' : 'BTN_RIGHT' },
248
+ 'XB1_RSX' : {'code' : 'KEY_RIGHT' , 'code_neg' : 'KEY_LEFT' },
249
+ 'XB1_RSY' : {'code' : 'KEY_DOWN' , 'code_neg' : 'KEY_UP' },
250
+ 'XB1_DPX' : {'code' : 'KEY_RIGHT' , 'code_neg' : 'KEY_LEFT' },
251
+ 'XB1_DPY' : {'code' : 'KEY_DOWN' , 'code_neg' : 'KEY_UP' },
252
+ 'XB1_X' : {'code' : 'BTN_LEFT' },
253
+ 'XB1_Y' : {'code' : 'BTN_RIGHT' },
254
+ 'XB1_MENU' : {'code' : 'KEY_ESC' },
255
+ 'XB1_VIEW' : {'code' : 'KEY_ESC' }
256
+ }
257
+
258
+ PLAYSTATION_DEFAULT_KB_MOUSE_MAPPING = {
259
+ 'PS5_CROSS' : {'code' : 'BTN_LEFT' },
260
+ 'PS5_SQUARE' : {'code' : 'BTN_LEFT' },
261
+ 'PS5_L1' : {'code' : 'BTN_LEFT' },
262
+ 'PS5_L2_BUTTON' : {'code' : 'BTN_LEFT' },
263
+
264
+ 'PS5_CIRCLE' : {'code' : 'BTN_RIGHT' },
265
+ 'PS5_TRIANGLE' : {'code' : 'BTN_RIGHT' },
266
+ 'PS5_R1' : {'code' : 'BTN_RIGHT' },
267
+ 'PS5_R2_BUTTON' : {'code' : 'BTN_RIGHT' },
268
+
269
+ 'PS5_LSX' : {'code' : 'REL_X' },
270
+ 'PS5_LSY' : {'code' : 'REL_Y' },
271
+
272
+ 'PS5_RSX' : {'code' : 'KEY_RIGHT' , 'code_neg' : 'KEY_LEFT' },
273
+ 'PS5_RSY' : {'code' : 'KEY_DOWN' , 'code_neg' : 'KEY_UP' },
274
+ 'PS5_DPX' : {'code' : 'KEY_RIGHT' , 'code_neg' : 'KEY_LEFT' },
275
+ 'PS5_DPY' : {'code' : 'KEY_DOWN' , 'code_neg' : 'KEY_UP' },
276
+
277
+ 'PS5_CREATE' : {'code' : 'KEY_ESC' },
278
+ 'PS5_OPTION' : {'code' : 'KEY_ESC' }
279
+ }
280
+
240
281
XBOX_DEFAULT_MAPPING = {
241
282
# buttons to buttons
242
283
'BTN_A' : {'code' :'IBM_GGP_BTN_1' },
@@ -284,10 +325,14 @@ def translate_dict(old_mapping_dict, lookup_dict):
284
325
285
326
def find_keycode_in_mapping (source_code , mapping_dict , usb_gamepad_type ):
286
327
map_dict_copy = dict (mapping_dict )
287
- if usb_gamepad_type == 'PlayStation' and map_dict_copy .get ("IS_DEFAULT" , False ) :
328
+ if usb_gamepad_type == 'PlayStation' and map_dict_copy .get ("MAPPING_TYPE" ) == "DEFAULT_15PIN" :
288
329
map_dict_copy = PLAYSTATION_DEAULT_MAPPING
289
- if usb_gamepad_type == 'Xbox' and map_dict_copy .get ("IS_DEFAULT" , False ) :
330
+ elif usb_gamepad_type == 'Xbox' and map_dict_copy .get ("MAPPING_TYPE" ) == "DEFAULT_15PIN" :
290
331
map_dict_copy = XBOX_DEFAULT_MAPPING
332
+ elif usb_gamepad_type == 'PlayStation' and map_dict_copy .get ("MAPPING_TYPE" ) == "DEFAULT_MOUSE_KB" :
333
+ map_dict_copy = PLAYSTATION_DEFAULT_KB_MOUSE_MAPPING
334
+ elif usb_gamepad_type == 'Xbox' and map_dict_copy .get ("MAPPING_TYPE" ) == "DEFAULT_MOUSE_KB" :
335
+ map_dict_copy = XBOX_DEFAULT_KB_MOUSE_MAPPING
291
336
source_name = usb4vc_shared .code_value_to_name_lookup .get (source_code )
292
337
if source_name is None :
293
338
return None , None
@@ -363,11 +408,13 @@ def make_generic_gamepad_spi_packet(gp_status_dict, gp_id, this_device_info, map
363
408
global prev_kb_output
364
409
global curr_mouse_output
365
410
axes_info = this_device_info ['axes_info' ]
366
- this_gamepad_name = this_device_info .get ('name' , '' ).lower ()
411
+ this_gamepad_name = this_device_info .get ('name' , '' ).lower (). strip ()
367
412
usb_gamepad_type = 'Generic USB'
368
413
if 'xbox' in this_gamepad_name or 'x-box' in this_gamepad_name :
369
414
usb_gamepad_type = 'Xbox'
370
- elif 'wireless controller' in this_gamepad_name :
415
+ elif 'sony' in this_gamepad_name and 'wireless controller' in this_gamepad_name :
416
+ usb_gamepad_type = 'PlayStation'
417
+ elif this_gamepad_name == 'wireless controller' :
371
418
usb_gamepad_type = 'PlayStation'
372
419
373
420
this_gp_dict = gp_status_dict [gp_id ]
0 commit comments