5

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".

enter image description here

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.

1 Answer 1

2

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 then keyup and having to worry about delays and all that jazz, just use key. This allows you to just chain keys together, like a boss:

xdotool key Down Down Down Right

If you find that's too quick, reintroduce your --delay but start from 12 and work up until it works.

2
  • Epiphany doesn't recognize the standard keystrokes sent through key. For example xdotool key Down Arrow doesn't move the character at all.
    – somethis
    Nov 25, 2013 at 15:02
  • and Reintroducing --delay with key only delivers movement if very long delays are used around 200 milliseconds.
    – somethis
    Nov 25, 2013 at 15:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .