Skip to content

Instantly share code, notes, and snippets.

@dylan-lom
Last active July 26, 2023 20:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylan-lom/f0a4edc598e3a738cfc9c34f1a7c5216 to your computer and use it in GitHub Desktop.
Save dylan-lom/f0a4edc598e3a738cfc9c34f1a7c5216 to your computer and use it in GitHub Desktop.
Fake PS3 controller fix & udev rule
DRIVER=="usb", SUBSYSTEM=="usb", ATTR{idVendor}=="045e", ATTR{idProduct}=="028e", RUN+="/usr/local/bin/fixcontroller.py"

This script makes a fake ps3 controller connect on linux as a gamepad (shows as Xbox 360 for me). More details here probably

fixcontroller.py is adapted from https://gist.github.com/dnmodder/de2df973323b7c6acf45f40dc66e8db3

You probably want to check that the script works correctly before you follow the steps below to make the changes permanent.

Install as a udev rule

chmod +x fixcontroller.py
cp fixcontroller.py /usr/local/bin/fixcontroller.py
cp 01-fixps3.rules /etc/udev/rules.d
udevadm control --reload
#!/usr/bin/env python3
import os
import sys
try:
# this is where pyusb got installed for me, but it wasn't in the path
# when udev called the script.
sys.path.append('/usr/local/lib/python3.9/dist-packages/')
import usb.core
import usb.util
except ImportError as e:
print("First, install the pyusb module with PIP or your package manager.")
sys.exit(1)
else:
if os.geteuid() != 0:
print("You need to run this script with sudo")
sys.exit()
dev = usb.core.find(find_all=True)
for d in dev:
if d.idVendor == 0x045e and d.idProduct == 0x028e:
print('Controller found... fixing now :)')
d.ctrl_transfer(0xc1, 0x01, 0x0100, 0x00, 0x14)
finally:
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment