I'm trying to automate critical moves in my favorite Boulderdash clone called "Epiphany" (available through Ubuntu Software Centre).
In the following example the character should move: 3x "Down Arrow" and 1x "Right Arrow".
Writing a script is pretty straightforward. Once launched it (1) sets focus to the game window and (2) sends the keystroke commands through Xdotool.
#!/bin/bash
# set focus to epiphany
xdotool search --onlyvisible --class epiphany windowactivate
sleep 0.5
# move down one unit
xdotool keydown --delay 100 Down Arrow; xdotool keyup --delay 12 Down Arrow
# move down one unit
xdotool keydown --delay 100 Down Arrow; xdotool keyup --delay 12 Down Arrow
# move down one unit
xdotool keydown --delay 100 Down Arrow; xdotool keyup --delay 12 Down Arrow
# move right one unit
xdotool keydown --delay 100 Right Arrow; xdotool keyup --delay 12 Right Arrow
But, this solution doesn't work consistently.
Sometimes the character only completes part of the move - e. g. only 2x "Down Arrow". At other times he moves too slow and is crushed by the diamond.
Are there any suggestions on how to solve this - preferrably using Xdotool?
Edit:
The straightforward commands like xdotool key Down Arrow
- as suggested - don't work. The character in the game doesn't move at all.
Reducing your delays seems like the obvious answer. The default is 12ms and you've boosted that to 100ms for your arrow presses, without explaining why.
And instead of using
keydown
thenkeyup
and having to worry about delays and all that jazz, just usekey
. This allows you to just chain keys together, like a boss:If you find that's too quick, reintroduce your
--delay
but start from 12 and work up until it works.