42

xdotool is a nice X application, I tend to use it for creating macro commands (like Alt+F4 or Ctrl+W or Ctrl+Alt+Backspace or something like that).

It's really easy to use and convenient, but I don't know of any Wayland compatible program like this. Is there any way to send mouse and keyboard input signals to Wayland right now similar to xdotool for X?

It works largely with XWayland right now, but not all commands work (such as Alt+F4, xev can even read the Alt+F4 input but it doesn't trigger the application termination like pressing it on the keyboard) there's also the matter of potentially not using XWayland.

4
  • 2
  • workaround for text entry, use xclip to save your text in the clipboard and press the middle mouse button to insert it. Two steps but works everywhere.
    – qwazix
    Commented Dec 22, 2020 at 17:53
  • @qwazix ... xdotool performs from a script like bash. Human action is not going to replace a script.
    – will
    Commented Jun 15, 2023 at 22:50
  • I am currently torn between selecting dotool and ydotool as an answer, they both do what I want. dotool has a very strange syntax (echo command | dotoolc?! what the hell?) but works really well. ydotool has a less strange syntax but seems currently less actively developed and more buggy. I feel like neither is the perfect answer, but both come reasonably close enough to be one.
    – Cestarian
    Commented Jan 23 at 1:15

5 Answers 5

14

There's currently no perfect solution, but there's a close one: ydotool.

It uses the uinput interface as backend, and has no dependency on display servers.

2
  • 1
    Sadly I couldn't make it run on Ubuntu 19.04. I installed libboost-program-options-dev, libevdevplus, libuinputplus and finally the ydotool itself, but I'm still getting ydotool: error while loading shared libraries: libboost_program_options.so.1.65.1: cannot open shared object file: No such file or directory
    – csha
    Commented Jun 20, 2019 at 10:40
  • Note: this requires root! Commented Aug 11, 2022 at 21:31
8

There's now another option for xdotool like functioality on Wayland, the wtype tool.

More details on the Wayland protocol used by wtype can be found in this blog post.

5
  • This is cool, sadly it has the reverse issue of using xdotool on xwayland; the issue that it doesn't work with xwayland D:
    – Cestarian
    Commented Jan 24, 2021 at 16:31
  • 1
    @Cestarian in what way doesn't it work for you with xwayland?
    – Maks
    Commented Jan 24, 2021 at 21:03
  • 1
    it says so on the git page u linked to, at the bottom of the readme: To support arbitrary unicode characters, wtype generates a keymap on the fly and submits it to the compositor for distribution. Unfortunately this is broken under Xwayland as X has an upper limit on the amount of defined keycode-keysym pairs. Am I maybe misunderstanding something? it works on xwayland? (I can't really test it right now because I don't have a wayland compositor set up)
    – Cestarian
    Commented Jan 27, 2021 at 23:12
  • I tried it under KDE neon Plasma Wayland session, but it didn't work, displaying this message: "Compositor does not support the virtual keyboard protocol"
    – Sadi
    Commented Dec 25, 2021 at 18:05
  • 1
    I tried wtype and it seems like, disappointingly, that the protocol it relies on (virtual-keyboard-unstable-v1) is currently supported by neither Gnome nor KDE. (See here).
    – cyqsimon
    Commented Aug 29, 2022 at 8:58
6

No, such features were explicitly excluded from the Wayland design for security reasons. (Reading other programs' input is the biggest problem, but allowing fake input to be sent to other programs can also lead to troubles.)

That said, I do expect some Wayland WMs to eventually implement some sort of macros feature; after all, they will need to support on-screen keyboards and voice control (for accessibility).

But if such a feature existed, it would depend on which Wayland compositor you're using: Weston? KDE's KWin? GNOME Shell? Enlightenment? There is no "display server – window manager" split in Wayland; the window manager is the Wayland server and decides which features to implement (either as Wayland sub-protocols or as D-Bus APIs or such).

8
  • 1
    It should be possible I think to create such a program that works for all wayland compositors. Libinput forwards user input to wayland, and it is through libinput that alt+f4 and other commands that use a wayland function can be triggered. All you have to do is trick libinput into reading a macro as a keyboard or mouse input; is what I think, but I have no idea how to do it myself.
    – Cestarian
    Commented Jan 28, 2016 at 21:08
  • 1
    it shouldn't be that difficult, I recall doing it in some driver work once, maybe if I just look at that code I could figure out some way. (Although I never knew what I was doing at the time)
    – Cestarian
    Commented Jan 29, 2016 at 7:50
  • 1
    There was a RFC on a mailing list: RFC: Interface for injection of input events and Add an API for taking screenshots and recording screencasts. It sounds like the challenges could be addressed with some additional security hardening work.
    – Ben Creasy
    Commented Feb 18, 2018 at 9:38
  • 1
    What's wrong with sending fake input? I understand the security issues with reading another programs input, but sending?
    – Lysol
    Commented Jul 11, 2020 at 6:56
  • 2
    Thankfully the constant parroting of "security reasons" did not prevent the wayland developers from adding an appropriate protocol: gitlab.freedesktop.org/mstoeckl/waypipe/blob/v0.1.0/protocols/…
    – Maks
    Commented Jan 24, 2021 at 6:34
2

There's dotool

Like ydotool it uses uinput so it's linux specific but independent of X11/Wayland, and even works in TTYs.

I wrote dotool because ydotool was only designed to run as root and requires a daemon.

1
  • 1
    Does dotool work on Gnome with Mutter?
    – user198350
    Commented Jun 10, 2023 at 10:19
1

I've just spent a couple of hours installing KDE 6 on Arch and installing dotool plus a new one, kdotool.

Between dotool for output and kdotool which uses kwin's scripting and dbus interfaces I can once again do the things I currently do with xdotool and devilspie2 on xfce. Check the windows names to filter actions in response to hotkeys, locate the mouse and move things where I want them and output clicks or text to the desired window.

I still have a major task after KDE 6 and Wayland are a little more stable and widely supported but I can now see a post X11 future that I'm happy with.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .