Any way to trigger evdev input switch through command line / script?

I’m messing around with voice command software and I’m trying to add a keyword that triggers a script that will switch the inputs on my evdev passthrough setup without having to physically press l-ctrl+r-ctrl. Is there anyway to do this? I tried

xdotool key Control_L+Control_R

and it didn’t work. Is there something I can pass to qemu directly to trigger the evdev switch?

Resolved with the power of Python:

#!/usr/bin/env python3

import evdev
import sys

dev = evdev.InputDevice('/dev/input/by-path/pci-0000:02:00.0-usb-0:1.3:1.0-event-kbd')

dev.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_LEFTCTRL, 1)
dev.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_RIGHTCTRL, 1)
dev.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_LEFTCTRL, 0)
dev.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_RIGHTCTRL, 0)
dev.write(evdev.ecodes.EV_SYN, 0, 0)
2 Likes