36

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.

Cestarian
  • 1,823
  • 6
  • 25
  • 45
  • 2
    See also https://unix.stackexchange.com/questions/381831/keyboard-emulation-in-wayland and https://askubuntu.com/questions/956640/equivalent-to-xdotool-for-wayland – Ben Creasy Feb 18 '18 at 09:31
  • 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 Dec 22 '20 at 17:53
  • @qwazix ... `xdotool` performs from a script like `bash`. Human action is not going to replace a script. – will Jun 15 '23 at 22:50

4 Answers4

11

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.

Satori Komeiji
  • 121
  • 1
  • 2
  • 1
    Sadly I couldn't make it run on Ubuntu 19.04. I installed `libboost-program-options-dev`, [`libevdevplus`](https://github.com/YukiWorkshop/libevdevPlus/releases), [`libuinputplus`](https://github.com/YukiWorkshop/libuInputPlus/releases) and finally the [`ydotool` itself](https://github.com/ReimuNotMoe/ydotool/releases), 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` – m93a Jun 20 '19 at 10:40
  • Note: this requires root! – VasyaNovikov Aug 11 '22 at 21:31
8

Therer is 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.

Maks
  • 181
  • 1
  • 4
  • 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 Jan 24 '21 at 16:31
  • 1
    @Cestarian in what way doesn't it work for you with xwayland? – Maks Jan 24 '21 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 Jan 27 '21 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 Dec 25 '21 at 18:05
  • 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](https://github.com/atx/wtype/issues/22#issuecomment-1113273742)). – cyqsimon Aug 29 '22 at 08:58
4

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).

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • 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 Jan 28 '16 at 21:08
  • @Cestarian: You would have to create a fake input device with the kernel's uinput feature. – u1686_grawity Jan 29 '16 at 07:34
  • 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 Jan 29 '16 at 07:50
  • 1
    There was a RFC on a mailing list: [RFC: Interface for injection of input events](https://lists.freedesktop.org/archives/wayland-devel/2017-March/033676.html) and [Add an API for taking screenshots and recording screencasts](https://bugs.freedesktop.org/show_bug.cgi?id=98894). It sounds like the challenges could be addressed with some additional security hardening work. – Ben Creasy Feb 18 '18 at 09:38
  • 1
    What's wrong with sending fake input? I understand the security issues with *reading* another programs input, but sending? – Lysol Jul 11 '20 at 06:56
  • 2
    Thankfully the constant parroting of "security reasons" did not prevent the wayland developers from adding an appropriate protocol: https://gitlab.freedesktop.org/mstoeckl/waypipe/blob/v0.1.0/protocols/virtual-keyboard-unstable-v1.xml – Maks Jan 24 '21 at 06:34
  • If you require special privileges such as root access for simulated device events, then it's kind of the user's decision whether to trust and enable the simulation isn't it? – matt Apr 05 '21 at 20:35
  • I wanted to mention Kde connect. It can use android smartphone as a mouse for your desktop, even in wayland. – Ashark May 18 '22 at 17:06
0

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.

geb
  • 1
  • 1