29

I'm looking for a solution working in Wayland to get mouse position, move it and click inside a bash script, all things xdotool can do for X server.

xdotool getmouselocation

is still working, but

xdotool mousemove 
xdotool click 

have no impact on the mouse cursor in GNOME Wayland session.

dessert
  • 39,982
mxdsp
  • 3,818

4 Answers4

9

There is the ydotool package for Wayland:

Package ydotool

Generic Linux command-line automation tool (no X!)

https://github.com/ReimuNotMoe/ydotool

Performs some of the functions of xdotool(1) without requiring X11 - however, it generally requires root permission (to open /dev/uinput)

Currently implemented command(s):

  • type - Type a string
  • key - Press keys
  • mousemove - Move mouse pointer to absolute position
  • click - Click on mouse buttons

N.B. optionally, you can enable and start the ydotoold daemon with:

  1. systemctl enable ydotool
  2. systemctl start ydotool
Pablo Bianchi
  • 15,657
9

This is because such features have been explicitly removed from Wayland for security reasons. The major concerns were reading other programs input and allowing fake input to be sent to other programs which would allow different attack vectors.

Some window-managers might implement some sort of macro feature in the future but as of now there is no such feature that I know of.

Implementing this would mean to implement it for each of the different window managers which surely will take still a while.

I suggest using Xorg instead of Wayland for now if you need to use such features.

dessert
  • 39,982
Videonauth
  • 33,355
  • 17
  • 105
  • 120
2

evemu from the evemu-tools package can emulate devices like mouse, touchpads and keyboards in wayland. It cannot "read" what is happening on the screen but can easily move & click and "blindly" interact with the session.

sudo evemu-describe # list devices

if your mouse is /dev/input/event5 from the output of above command the following will move mouse 50 pixels xy then right-press & let go of button:

sudo evemu-event /dev/input/event5 --type EV_REL --code REL_X --value 50
sudo evemu-event /dev/input/event5 --type EV_REL --code REL_Y --value 50 
sudo evemu-event /dev/input/event5 --type EV_KEY --code BTN_RIGHT --value 1 
sudo evemu-event /dev/input/event5 --type EV_KEY --code BTN_RIGHT --value 0

You can also record a particular sequence and re-play it:

# press ctrl-c to stop recording
sudo evemu-record /dev/input/event5 /tmp/mouse-sequence

to replay session

sudo evemu-play /tmp/mouse-sequence

Pablo Bianchi
  • 15,657
tomodachi
  • 14,832
2

There is the wtype package for Wayland. It's available on apt repos on Ubuntu 22.04.

Seems a simpler approach (no need for ydotoold/systemd service), but for the time being, mutter (GNOME compositor) doesn't work with it.

Check also Evemu, a freedesktop project that records and replays device descriptions and events.

Pablo Bianchi
  • 15,657