Wayland in 26.04, how to convert script from X11 to Wayland?
https://askubuntu.com/questions/1566591/wayland-in-26-04-how-to-convert-script-from-x11-to-waylandI have a script I use to allow me to plug in a second keyboard and change what keys are sent when pressed. I use it to send key combinations that execute macros in my audio editing software. It's become a vital part of my workflow. Here is the script:
#!/usr/bin/env python3
import os
from evdev import InputDevice, categorize, ecodes
#dev = InputDevice('/dev/input/event6') # Do not use event numbers for identifying keyboard as they change with reboots.
dev = InputDevice('/dev/input/by-id/usb-CHESEN_USB_Keyboard-event-kbd') # Use IDs for identifying keyboard as they do not change with reboots.
dev.grab()
for event in dev.read_loop():
if event.type == ecodes.EV_KEY:
key = categorize(event)
if key.keystate == key.key_down:
if key.keycode == 'KEY_ESC':
os.system("xte 'keydown Control_L' 'keydown KP_0' 'keyup KP_0' 'keyup Control_L'") # Fill TS with 50ms roomtone
elif key.keycode == 'KEY_F1':
os.system("xte 'keydown Control_L' 'keydown KP_1' 'keyup KP_1' 'keyup Control_L'") # Fill TS with 100ms roomtone
elif key.keycode == 'KEY_F2':
os.system("xte 'keydown Control_L' 'keydown KP_2' 'keyup KP_2' 'keyup Control_L'") # Fill TS with 150ms roomtone
How do I change this script to work with Wayland? As I understand it, it uses things like evdev and xte, not sure what else, which don't work in Wayland.
In looking into this, I've seen reference to an issue with the commands sending multiple keys rather than the lines of the script being for simple substitutions. I don't see anywhere how to deal with this in Wayland.
I'm not a coder by a long shot and no longer remember how this was put together.












