How to simulate pressing multiple keys together on Linux?

This post introduces a key presser on Linux with xvkb. But how to simulate pressing multiple keys together on Linux?

That is, I would like to have multiple keys such as “A” “B” “C” “D” pressed together and being hold. How to simulate this on Linux with programs/commands?

You can make use of xdotool (xdotool: command-line X11 automation tool) to simulate the keyboard pressing.

The command for pressing ABCD together will be:

xdotool sleep 5 keydown a keydown b keydown c keydown d

It will first sleep 5 seconds for you to click to focus on the target program’s window. Then it will press down a b c and d (not release them anymore).

After you would like to release these keys. Just kill the xdotool instance by pressing Ctrl-C in the terminal.

Note: you will need to press abcd once again more on your keyboard to actually release these keys.

Answered by Eric Z Ma.

Eric Z Ma

Eric is a father and systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *