alt+esc on joystick yellow click

This commit is contained in:
valere
2025-09-27 16:33:40 +02:00
parent e1b525eaa1
commit e1db401b58

View File

@@ -3,15 +3,15 @@ import evdev
import uinput import uinput
import subprocess import subprocess
import time import time
import os
DEVICE_NAMES = ["8BitDo NGC Modkit"] DEVICE_NAMES = ["8BitDo NGC Modkit"]
BUTTON_MAP = { BUTTON_MAP = {
"304": "KEY_ENTER", "304": "KEY_ENTER", # A
"305": None, "305": None, # B (non utilisé)
"311": "KEY_LEFTALT", "311": "KEY_LEFTALT", # R
"307": "KEY_RIGHT", "307": "KEY_RIGHT", # Stick droit → Droite
"308": "KEY_LEFT", "308": "KEY_LEFT", # Stick droit → Gauche
# 318 (BTN_THUMBR) sera géré à part
} }
events = [ events = [
@@ -39,8 +39,6 @@ def is_dolphin_running():
except Exception: except Exception:
return False return False
pressed_keys = set()
def handle_device(dev_path): def handle_device(dev_path):
dev = evdev.InputDevice(dev_path) dev = evdev.InputDevice(dev_path)
try: try:
@@ -50,24 +48,20 @@ def handle_device(dev_path):
key_code = str(event.code) key_code = str(event.code)
# mettre à jour l'état des touches pressées # cas spécial : joystick jaune (BTN_THUMBR, code 318)
if event.value == 1: if key_code == "318" and event.value == 1: # pression
pressed_keys.add(key_code)
elif event.value == 0:
pressed_keys.discard(key_code)
# logique R + B → Alt+Esc
if "311" in pressed_keys and "305" in pressed_keys:
keyboard.emit(uinput.KEY_LEFTALT, 1) keyboard.emit(uinput.KEY_LEFTALT, 1)
keyboard.emit(uinput.KEY_ESC, 1) keyboard.emit(uinput.KEY_ESC, 1)
keyboard.emit(uinput.KEY_ESC, 0) keyboard.emit(uinput.KEY_ESC, 0)
keyboard.emit(uinput.KEY_LEFTALT, 0) keyboard.emit(uinput.KEY_LEFTALT, 0)
else: continue
# envoyer les touches normales sauf celles mappées à None
if key_code in BUTTON_MAP: # touches normales selon le mapping
mapped_key = BUTTON_MAP[key_code] if key_code in BUTTON_MAP:
if mapped_key is not None: # uniquement si mapped_key n'est pas None ou vide mapped_key = BUTTON_MAP[key_code]
keyboard.emit(getattr(uinput, mapped_key), event.value) if mapped_key is not None:
keyboard.emit(getattr(uinput, mapped_key), event.value)
except OSError: except OSError:
dev.close() dev.close()
raise raise