Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial: how to install and use ydotool #207

Open
ElectricRCAircraftGuy opened this issue Jun 18, 2023 · 19 comments
Open

Tutorial: how to install and use ydotool #207

ElectricRCAircraftGuy opened this issue Jun 18, 2023 · 19 comments

Comments

@ElectricRCAircraftGuy
Copy link

ElectricRCAircraftGuy commented Jun 18, 2023

You might consider linking to this in your documentation. This was a lot of work for me to figure it out, so I think it will be useful to many people:

Tutorial: Getting started with ydotool to automate key presses (or mouse movements) in Linux

I go over installation, launching the daemon in a way that doesn't require your user to use root to connect to it, pressing key sequences, and where to find them, how to view the help menus, etc.

@rwjack
Copy link

rwjack commented Jun 19, 2023

Just in time, I was getting lost trying to install it.

Still having trouble finding how to simulate arrow keys.

Oh, it's just KEY_RIGHT

@ElectricRCAircraftGuy
Copy link
Author

ElectricRCAircraftGuy commented Jun 19, 2023

@rwjack , yeah, it appears to be KEY_RIGHT, or key code 106, as shown here: https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h#L181

You can view all key codes locally with:

gedit /usr/include/linux/input-event-codes.h

For full instructions to press and release KEY_RIGHT, it should be this:

# Kill the `ydotoold` background running processes
sudo pkill ydotoold

# start the background daemon
sudo -b ydotoold --socket-path="$HOME/.ydotool_socket" --socket-own="$(id -u):$(id -g)"

# press key right, then release it
YDOTOOL_SOCKET="$HOME/.ydotool_socket" ydotool key 106:1 106:0

I don't mention it in my article, but you can also add that environment variable to the bottom of your ~/.bashrc file, as this:

export YDOTOOL_SOCKET="$HOME/.ydotool_socket"

Then you could just run this in place of the last command above:

ydotool key 106:1 106:0

@rwjack
Copy link

rwjack commented Jun 19, 2023

@ElectricRCAircraftGuy Kudos! Thanks bud

@ecspresso
Copy link

ecspresso commented Sep 18, 2023

@ElectricRCAircraftGuy That was a great guide, thank you. I made a script (that i have named ydotool-manage on my computer) based on your guide to start, stop and update from one place.

#!/bin/sh

if [ $# -ne 1 ] || ( [ "$1" != "start" ] && [ "$1" != "stop" ] && [ "$1" != "update" ] && [ "$1" != "status" ] );then
    echo "`basename $0`: missing OPTION
Usage: `basename $0` [OPTION]

    '`basename $0` start' to start the ydotool service.
    '`basename $0` stop' to stop the ydotool service
    '`basename $0` update' to update (or install) ydotool."
  exit 1
fi

# Visa status
if [ "$1" = "status" ]; then
    sudo systemctl status ydotool.service
fi

# Start ydtoold
if [ "$1" = "start" ]; then
    sudo systemctl start ydotool.service
    sudo systemctl status ydotool.service
fi

# Stop ydtoold
if [ "$1" = "stop" ]; then
    sudo systemctl stop ydotool.service
    sudo systemctl status ydotool.service
fi

# Update (update git folder, build and make install) ydotool and ydotoold.
if [ "$1" = "update" ] ; then
    sudo -v

    # pre reqs
    sudo apt update && sudo apt install cmake scdoc pkg-config

    # Check if ydotool repo is downloaded
    if [ ! -d /opt/ydotool ]; then 
        cd /tmp
        git clone https://github.com/ReimuNotMoe/ydotool.git
        sudo mv /tmp/ydotool/ /opt/
    fi

    cd /opt/ydotool/

    # Get latest version
    git pull

    # Make
    mkdir -p build && cd build
    cmake ..
    time make -j "$(nproc)"

    # Install
    sudo make install

    # Remove the need for sudo
    sudo chmod +s $(which ydotool)

    # Install systemd service
    sudo rm /etc/systemd/system/ydotool.service
    sudo ln -s /usr/lib/systemd/user/ydotool.service /etc/systemd/system/
    # Reload the systemd daemon
    sudo systemctl daemon-reload
    # Reload enable the service
    sudo systemctl enable ydotool
    # Reload start ydotool
    sudo systemctl start ydotool
    # Check that it is running
    sudo systemctl status ydotool

    echo "ydotoold version: $(ydotoold --version)"
    echo ""

    if ! grep -q 'export YDOTOOL_SOCKET="/tmp/.ydotool_socket"' $HOME/.profile; then
        echo '' >> "$HOME/.profile"
        echo '# ydotoold socket location' >> "$HOME/.profile"
        echo 'export YDOTOOL_SOCKET="/tmp/.ydotool_socket"' >> "$HOME/.profile"
        echo "YDOTOOL_SOCKET is being exported in $HOME/.profile."
        echo "Please relog to enable the new profile settings."
    fi

fi

EDIT: Now properly installs the service.
More information here https://askubuntu.com/questions/1413829/how-can-i-install-and-use-the-latest-ydotool-keyboard-automation-tool-working-o

EDIT 2: Enable the service after installing it.

EDIT 3: Forgot to install cmake scdoc pkg-config

@ElectricRCAircraftGuy
Copy link
Author

ElectricRCAircraftGuy commented Sep 18, 2023

@ecspresso , nice job. There are still more things I don't know. Using systemd to stop/start/restart it may be better. Check out this comment here (all the comments under my answer): https://askubuntu.com/questions/1470593/how-can-i-write-a-program-to-press-keys-such-as-windows-d-in-wayland-repla#comment2596097_1473061

@ecspresso
Copy link

I can see people talking about the service but it seems to be missing for me.

@ecspresso
Copy link

I found this where someone explains how to build and install ydotool in detail. It is also explained how to add the service.

I have updated my above script.

@Paiusco
Copy link
Contributor

Paiusco commented Mar 6, 2024

@ElectricRCAircraftGuy if you have time, let's update that guide, split them into how to install and a use guide? I can help with that. Then we can move towards submitting a PR mentioning those links as a guide

@shellheim
Copy link

shellheim commented Apr 25, 2024

I had it working in a previous system but didn't write it down so wasted quite a few hours figuring it out again, so I did write up here.

@Paiusco
Copy link
Contributor

Paiusco commented Apr 28, 2024

@shellheim I think there are some improvements. I'm wondering that even the ydotool.service is now named ydotoold.service

You also don't need to chown on the socket created, ydotoold accepts this as a parameter when run, so you can edit the service file so you're the owner of the socket, or even change the permission (similar to what a chmod would do), so even that you're not the owner, you can still access the socket

@shellheim
Copy link

shellheim commented Apr 28, 2024

@Paiusco Man, I am so damm grateful to you. Thank you very much. I had completely forgotten about that flag. I am gonna fix the gist in the morning. Again, thank you very much!

edit: the gist should be much better by now.

@ReimuNotMoe ReimuNotMoe pinned this issue Apr 28, 2024
@ReimuNotMoe
Copy link
Owner

Thanks so much for your contribution, I'm very grateful.

I have pinned this issue now.

@ElectricRCAircraftGuy
Copy link
Author

ElectricRCAircraftGuy commented Apr 30, 2024

@ElectricRCAircraftGuy if you have time, let's update that guide, split them into how to install and a use guide? I can help with that. Then we can move towards submitting a PR mentioning those links as a guide

I'm not going to have time :(

I'm a single dad now, and sole income. (And this is lower priority on my list.)

@Edwardius
Copy link

Edwardius commented May 20, 2024

Is it not possible to make installation as compact as apt install ydotool?

@Paiusco
Copy link
Contributor

Paiusco commented May 21, 2024

@Edwardius if you look at #233 you'll see that the package that debian-like distro currently ships is 5years old, so this is controlled by the distro/repo and not by us.
If you want to get something newer, you may move to a "rolling distro" instead.

@superstes
Copy link

Note: If you are on ubuntu/debian you can also (try) to download the binaries from the releases page instead of needing to compile it.

@superstes
Copy link

superstes commented Nov 21, 2024

I've also just written a basic setup-guide: https://docs.o-x-l.com/automation/ydotool.html
An example for compiling via docker is included.
Repo: https://github.com/O-X-L/docs

@KAGEYAM4
Copy link

KAGEYAM4 commented Dec 3, 2024

Anyidea how to run ydotoold in ArchLinux?

$ systemctl --user cat ydotool.service 
# /usr/lib/systemd/user/ydotool.service
[Unit]
Description=Starts ydotoold service

[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/ydotoold
ExecReload=/usr/bin/kill -HUP $MAINPID
KillMode=process
TimeoutSec=180

[Install]
WantedBy=default.target
$ systemctl --user status ydotool.service 
× ydotool.service - Starts ydotoold service
     Loaded: loaded (/usr/lib/systemd/user/ydotool.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Tue 2024-12-03 10:20:00 IST; 10s ago
   Duration: 66ms
 Invocation: e3c30db428524550bca9963456a953d3
    Process: 1551 ExecStart=/usr/bin/ydotoold (code=exited, status=2)
   Main PID: 1551 (code=exited, status=2)

Dec 03 10:20:00 ArchLinux systemd[1395]: ydotool.service: Scheduled restart job, restart counter is at 5.
Dec 03 10:20:00 ArchLinux systemd[1395]: ydotool.service: Start request repeated too quickly.
Dec 03 10:20:00 ArchLinux systemd[1395]: ydotool.service: Failed with result 'exit-code'.
Dec 03 10:20:00 ArchLinux systemd[1395]: Failed to start Starts ydotoold service.

 $ ydotoold
You're advised to run this program as root, or YMMV.
failed to open uinput device: Permission denied

Its asking for sudo, if i directly run it from terminal. Then in consideration with above user-service file, how can i achieve sudo.

Also there's another program kando which can send keypress, but it dosen't requre sudo. Anyway to make ydotoold work without sudo per-user basis?

@shellheim
Copy link

change the ExecStart start line :

ExecStart=/usr/bin/ydotoold --socket-own=1000:984

You will have your numbers, to get them run

echo $(id -u):$(id -g)

then sudo restart the file, it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants