11

Is there a way to make xdotool or xte or any other alternative to work in Fedora 26? I'm trying to emulate keypresses (using xbindkeys), e.g. pressing Alt+B would emulate pressing Ctrl+Shift+B. But apparently neither xdotool nor xte work in Wayland (for security reasons [?])

Is there a workaround? Otherwise how do I rebind keys to other keys?

iLemming
  • 533
  • 2
  • 6
  • 14
  • 2
    See also https://superuser.com/questions/1032270/wayland-alternative-for-xorgs-xdotool and https://askubuntu.com/questions/956640/equivalent-to-xdotool-for-wayland – Ben Creasy Feb 18 '18 at 09:32

2 Answers2

12

I'm using this little script. It needs the package evemu installed and sudo-confguration for evemu-event without password-notification. EVDEVICE is the device used to emulate the input. /dev/input/event8 is my keyboard (use sudo evemu-record to find yours)

#!/bin/bash
# keycomb.sh

EVDEVICE=/dev/input/event8

for key in $@; do
    sudo evemu-event $EVDEVICE --type EV_KEY --code KEY_$key --value 1 --sync
done


# reverse order
for (( idx=${#@}; idx>0; idx-- )); do
    sudo evemu-event $EVDEVICE --type EV_KEY --code KEY_${!idx} --value 0 --sync
done

you can e.g. change a tab with ./keycomb.sh RIGHTCTL PAGEDOWN.

Please note: This script does no validation on parameters, use with care ;)

EDIT Feb 2021: Finally I found a project doing it right: https://github.com/sezanzeb/key-mapper

blaimi
  • 1,120
  • 1
  • 7
  • 10
  • Finally got the nice project working on Fedora/Wayland/GNOME after probably `xte` was not helping with `xbindkeys` or isolated, and maybe a small attempt with `evemu-event`. After `pip` and about 4 `systemtl` commands, I also needed this command after some GUI configuration: `sudo key-mapper-control --command start --device "" --preset ""` – Pysis Dec 14 '21 at 22:14
7

This is too long for a comment, but not really an answer... I recently came across some python code which says

Simple script to replace xdotool when using Gnome/Wayland for entering keystrokes using evdev.

which could be a starting point. I have not tried it. It needs the python package evdev, and has to run as user root.

There is also an evemu package which says

evemu records and replays device descriptions and events, making it possible to emulate input devices through the kernel's input system. Emulated devices are for most practical purposes indistinguishable from real devices.

meuh
  • 49,672
  • 2
  • 52
  • 114