32leaves.net

X11 automation during a presentation

The other day I was giving a presentation at UnFUG (during the Pimp my x86_64 lighting talk session). What I presented was exclusively console based. And as a programmer I love things I can automate, like typing during a presentation. So I wrote a little Ruby script to do the job for me and bound it to some key-strokes using my window manager on the eeePC. That thing is even able to fake typos, and has some random timing to not let the typing become to regular and fluent. In order to run this script below you’ll need the xdotool.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def play(text, type_speed)
    escape = false
    text.split("\n").each{|l| l.scan(/./).each {|c|
        if c == '!'
            escape = true
        elsif escape
            if c == '<'
                `xdotool keyup BackSpace`
                sleep (rand / 10)
            elsif c[0] - '0'[0] > 0
                sleep (c[0] - '0'[0]) / 10.0
            end
            escape = false
        else
            `xdotool type "#{c}"`
        end
        sleep type_speed + ((rand / 100) * (rand > 0.5 ? -1 : 1))
    }
   `xdotool keyup Return`
    }

end

play STDIN.readlines.join, 0.09

The script has some sort of escape/ex mode to be able to place some commands. The following snipped uses them (watch out for the ! chars):

1
2
3
4
5
ruby session.rb

!5
nr :base, 42,-1,0.2,5,16,EUU!<CLID
!1play

Possible use-cases:

  • stunningly fast typing with one hand
  • telekinesis like typing

All in all it’s just a cool effect :)

Fork me on GitHub