Keyboard emulation in Wayland

5,280

Solution 1

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

Solution 2

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.

Share:
5,280

Related videos on Youtube

iLemming
Author by

iLemming

Currently not available for hire

Updated on September 18, 2022

Comments

  • iLemming
    iLemming almost 2 years

    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?

  • Pysis
    Pysis over 2 years
    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 "<keyboard>" --preset "<preset>"