Ubuntu – Does `xdotool key –delay` pause for specified delay between typing every two consecutive keys

xdotool

manpage of xdotool says

— delay milliseconds Delay between keystrokes. Default is 12ms.

I thought that key string will type each character in the string once, and --delay is for pause between typing two consecutive characters. So why do the following first two commands not show typing anything, while the third types twice, and the last types many times? Thanks.

$ xdotool key 9
$ xdotool key --delay 2 9
$ xdotool key --delay 1000 9
99$ xdotool key --delay 10000 9
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999^C

I am using Lubuntu 18.04 and

$ xdotool -v
xdotool version 3.20160805.1

Best Answer

The manual indeed says

Delay between keystrokes. Default is 12ms.

This leads to expect that between each (simulated) press and release of a key, there will be a delay by the set value. The option, however, behaves rather as if the key is pressed during the period indicated by the delay, with no such delay in between different key presses. When the delay is long enough, autorepeat kicks in and the character is repeated.

To obtain the desired behavior where there is a pause between keypresses, one should rather use the sleep command:

xdotool sleep 1 key 9

9 will be pressed after one second. Two consecutive keypresses one second apart can be issued by

xdotool sleep 1 key 9 sleep 1 key 2

Alternatively, when working with bash scripts, a delay can be introduced using the bash sleep command between invocations of xdotool.

#!/bin/sh
sleep 1
xdotool key 9
sleep 1
xdotool key 2
Related Question