I figured it out. Thank you very much to @Rinzwind for pointing out the existence of ydotool
!
Here's how to have ydotool
press Windows + D. It works in both X11 and Wayland!
I first wrote about this on my website here: Tutorial: Getting started with ydotool to automate key presses (or mouse movements) in Linux.
For full details, see my article. Here are the key parts, copied directly from my article above:
First, build and install it:
# install dependencies
sudo apt update
sudo apt install git cmake scdoc
build ydotool
See: https://github.com/ReimuNotMoe/ydotool#build
git clone https://github.com/ReimuNotMoe/ydotool.git
cd ydotool
mkdir build
cd build
cmake .. # takes < 1 second
time make -j "$(nproc)" # takes < 1 second
sudo make install
Note: the install command installs here:
-- Install configuration: ""
-- Installing: /usr/local/bin/ydotoold
-- Installing: /usr/local/bin/ydotool
-- Installing: /usr/lib/systemd/user/ydotool.service
-- Installing: /usr/local/share/man/man1/ydotool.1
-- Installing: /usr/local/share/man/man8/ydotoold.8
See the man pages for help, and to prove to yourself it is installed
man ydotool # for the main program
man ydotoold # for the background daemon process
help menu
ydotool -h # for the main program
ydotoold -h # for the background daemon process [VERY HELPFUL MENU!]
check the version; my output is v1.0.4-0-g57ba7d0
ydotoold --version
Now, use it: have ydotool
press Windows + D
# 1. start the `ydotoold` background daemon (`sudo -b` runs it in the
# background; see `sudo -h`).
# - It takes a couple seconds to fully start up and print "READY". Once it does
# that, hit Enter a couple times to clear out the command line.
sudo -b ydotoold --socket-path="$HOME/.ydotool_socket" --socket-own="$(id -u):$(id -g)"
2. Use ydotool
- Have ydotool press Windows + D once to hide all windows, then make it wait 2
seconds, then have it press Windows + D again to show all windows:
YDOTOOL_SOCKET="$HOME/.ydotool_socket" ydotool key 125:1 32:1 32:0 125:0;
sleep 2;
YDOTOOL_SOCKET="$HOME/.ydotool_socket" ydotool key 125:1 32:1 32:0 125:0
3. Additional commands you may need: to show, kill, and help
See the ydotoold
background running processes
ps auxf | grep ydotoold
Kill the ydotoold
background running processes
sudo pkill ydotoold
View the ydotool
main help menu, including a list of all sub-commands.
ydotool -h
View the ydotool
sub-command help menus.
- Bug ( https://github.com/ReimuNotMoe/ydotool/issues/206 ): the daemon must
be running first to see these help menus!
YDOTOOL_SOCKET="$HOME/.ydotool_socket" ydotool key -h
YDOTOOL_SOCKET="$HOME/.ydotool_socket" ydotool click -h
YDOTOOL_SOCKET="$HOME/.ydotool_socket" ydotool mousemove -h
etc.
Open the Linux C header file containing all available key codes that ydotool
can press
gedit /usr/include/linux/input-event-codes.h
You can also see all possible key codes in this file online: https://github.com/torvalds/linux/blob/master/include/uapi/linux/input-event-codes.h.
Again, for more details, see my website: Tutorial: Getting started with ydotool to automate key presses (or mouse movements) in Linux.
See also
- How can I add "Show desktop" to the GNOME dash or Ubuntu Dock?
- @AndAC's excellent
wmctrl
answer
- my spin on the
wmctrl
answer, relying on my eRCaGuy_dotfiles repo I have with scripts in it.
- Q&A: How can I install the latest ydotool 1.0.1 (keyboard automation tool working on Wayland) in Ubuntu 22.04?
ydotool
, I got it! It's complicated. I'll write about it tomorrow hopefully. – Gabriel Staples Jun 04 '23 at 08:45ydotool
. – Gabriel Staples Jun 04 '23 at 08:52