With the advent of Wayland, automation utilities like xdotool, which are designed for Xorg, do not anymore work. ydotool is a keyboard automation tool that works independent of the display manager, i.e., it works on both Wayland and Xorg.
Following are installation instructions I tested on Ubuntu 22.04. Credits to here for the compilation instructions using cmake.
1. Prerequisites
1.1 Make sure you have the necessary tools for compilation.
# Needed for compilation
sudo apt install cmake scdoc pkg-config
1.2 In Debian based distributions, checkinstall can be used to package the compiled code into a .deb file instead of moving the compiled files directly into the system directories. That way, the custom compiled program is known in the package management system, and can easily be removed again if desired.
# For generating an installable .deb file
sudo apt install checkinstall
1.3 Optional: Install git to clone from git. Alternatively, you can download and unpack the .zip file from the github page.
# Optional: git to clone the repository instead of downloading zip
sudo apt install git
2. Downloading and compiling
2.1 Download the source code using the git tool.
git clone https://github.com/ReimuNotMoe/ydotool
Alternatively, download and unpack the zip file from the github page
2.2 Compilation
cd ydotool ## This will be `ydotool-master` if you extracted the zip file
mkdir build && cd build
cmake ..
make -j `nproc`
3. Installation
Instead of a classical sudo make install to install the compiled files into the system directories, checkinstall can be used on Debian based systems. checkinstall creates a .deb file which then can be installed using the APT package manager. Thus, the package management system knows about the package, and the package can easily be removed again using the package manager.
3.1 Start the tool
sudo checkinstall --fstrans=no
3.2 Accept the default answer on the prompt
The package documentation directory ./doc-pak does not exist.
Should I create a default set of package docs? [y]:
3.3 Enter a description for the package
Please write a description for the package.
End your description with an empty line or EOF.
>>
for example: Keyboard automation utility - custom install
3.4 Change the name of the package to something more meaningfull: on the prompt
This package will be built according to these values:
enter 2 to change the package name to e.g. ydotool-custom. Thus, the package will be easily recognized later, and there will be no name conflict with the Ubuntu provided package.
3.5 Again accept the default answer, n, on the prompt
Some of the files created by the installation are inside the home directory: /home
You probably don't want them to be included in the package.
Do you want me to list them? [n]:
3.6 However, answer y on the next question
Should I exclude them from the package? (Saying yes is a good idea) [n]:
although answering no and leaving these files in probably does not hurt at all.
After this, the .deb is created and automatically installed. It could be reinstalled later with the command sudo apt install <path-to-debfile>.
4. Configuration
4.1 ydotool must run a root. There are probably more modern ways to allow a user to start the utility without using sudo, but the old trick is to set the suid bit on the executable.
# Set the suid bit so ydotool can be run by any user
sudo chmod +s $(which ydotool)
Edit : Running as user : Step 4.1 can be skipped
4.2 With the application, a systemd service is installed. Enable and install it:
# Have the the newly installed service recognized, enabled and started
sudo systemctl daemon-reload
sudo systemctl enable ydotoold
sudo systemctl start ydotoold
Edit : Running as user : systemctl --user enable ydotoold.service && systemctl --user start ydotoold.service
4.3 The daemon expects the socket through which ydotool communicates on /tmp/.ydotool_socket. When run as user, ydotool looks for /run/user/<uid>/.ydotool_socket. One could make a symbolic link to /tmp/.ydotool_socket. Alternatively, you can set a variable YDOTOOL_SOCKET to indicate the socket to use.
Edit : Running as user :
export YDOTOOL_SOCKET=/run/user/$UID/.ydotool_socket
5. Test if it works
5.1 Log out then back in to have the environment variable take effect.
5.2 Open a terminal and test with following command:
ydotool type Ubuntu
The letters "Ubuntu" should be typed before your prompt reappears.