Skip to content

Instantly share code, notes, and snippets.

@chirvo
Last active February 22, 2023 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chirvo/e7365574b961805b8e0966b30bc561d6 to your computer and use it in GitHub Desktop.
Save chirvo/e7365574b961805b8e0966b30bc561d6 to your computer and use it in GitHub Desktop.
Spoof Device Python 3 script, based on the one found in the Star Citizen LUG wiki
#!/usr/bin/env python3
# See the original script at https://github.com/beniwtv/evdev-spoof-device
# Read https://github.com/starcitizen-lug/knowledge-base/wiki/Sticks,-Throttles,-&-Pedals
#
import evdev
import sys
from evdev import ecodes
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
if not devices:
print('Error: No evdev devices found on your system.',
'Check your evdev installation and device permissions.')
sys.exit(1)
if "--list-devices" in sys.argv:
print("\nAvailable devices:")
print("==============================================================")
print("Path (Name)")
print("================== ===========================================")
for device in devices:
print(device.path, "(" + device.name + ")")
print("================= ============================================\n")
sys.exit(0)
if "-d" in sys.argv:
inputDevice = sys.argv[sys.argv.index("-d") + 1]
for device in devices:
if device.path == inputDevice:
break
else:
print('Error: Device', inputDevice, 'not found')
sys.exit(1)
else:
print("\nUsage:\n")
print(" ", sys.argv[0], "-d <device>\n")
print(" ", sys.argv[0], "--list-devices\n")
sys.exit(0)
print("Using: " + device.path + " (" + device.name + ")")
caps = {
ecodes.EV_MSC: [ecodes.MSC_SCAN],
ecodes.EV_ABS: [ecodes.ABS_X, ecodes.ABS_Y],
ecodes.EV_KEY: [ecodes.BTN_JOYSTICK, ecodes.BTN_TRIGGER]
}
deviceCapabilities = device.capabilities()
if ecodes.EV_ABS in deviceCapabilities:
caps[ecodes.EV_ABS] += deviceCapabilities[ecodes.EV_ABS]
if ecodes.EV_KEY in deviceCapabilities:
caps[ecodes.EV_KEY] = deviceCapabilities[ecodes.EV_KEY]
spoofDevice = evdev.uinput.UInput(events=caps,
name=device.name + " PRO",
vendor=device.info.vendor,
product=device.info.product,
version=device.info.version)
print("Spoofing:", spoofDevice)
print("Mirroring events. Press Ctrl-C twice to exit.")
for event in device.read_loop():
spoofDevice.write_event(event)
spoofDevice.syn()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment