Mouse / Keyboard Automation for Linux

Friday, 10 July, Year 7 d.Tr. | Author: Mircea Popescu

Suppose your favourite videogame/MiMORPG decides to take almost two minutes per manufactured Leaky Treebark Flask, just as you had bought 80 Wooly Mushrooms which need 80 flasks made to then be turned into Improbable Oil via the world renowned Improbable Oil Schenectady. So that's like six hours or some shit right there, not to mention the Pointy Clumps of Slag and all that jazz. You're looking at two days to digest those sweet, sweet, delicious Wooly Mushrooms! And suppose further you can't just get pissed off at the devs and leave, for... congenital reasons, so to speak.

What the fuck do you do then ?!

Well, here's what I did :

  1. apt-get install xmacro, which is a few C++ scripts that make use of the horribly insecure construction that is the X window system.

  2. xmacrorec2 > herp.txt, after which you proceed to switch back to game, click "Collect All", then shift-clickii the Disgusting Goop into the craft table, then click the Treebark Shavings pileiii and type a 2 so it now reads 12 then drag it over, then click on the Coarse Frangible Thread pile, delete the 12, put in a 3 and move it over.

  3. sed /\n/\nDelay 0.2\n/ to introduce delays everywhere because somehow xmacro hasn't thought of this.

  4. nano herp.txt, which should look at this point something like

    MotionNotify 1055 522
    Delay 0.6
    ButtonPress 1
    Delay 0.6
    ButtonRelease 1
    Delay 0.6
    MotionNotify 920 520
    Delay 0.6
    KeyStrPress Shift_L
    Delay 0.6
    ButtonPress 1
    Delay 0.6
    ButtonRelease 1
    Delay 0.6
    MotionNotify 1135 535
    Delay 0.6
    KeyStrRelease Shift_L
    Delay 0.6
    MotionNotify 1145 530
    Delay 0.6
    ButtonPress 1
    Delay 0.6
    ButtonRelease 1
    Delay 0.6
    MotionNotify 914 570
    Delay 0.6
    ButtonPress 1
    Delay 0.6
    ButtonRelease 1
    Delay 0.6
    KeyStrPress 2
    Delay 0.1
    KeyStrRelease 2
    Delay 0.6
    MotionNotify 870 618
    Delay 0.6
    ButtonPress 1
    Delay 0.6
    ButtonRelease 1
    Delay 0.6
    MotionNotify 1129 563
    Delay 0.6
    ButtonPress 1
    Delay 0.6
    ButtonRelease 1
    Delay 0.6
    MotionNotify 921 618
    Delay 0.6
    ButtonPress 1
    Delay 0.6
    ButtonRelease 1
    Delay 0.6
    KeyStrPress BackSpace
    Delay 0.2
    KeyStrRelease BackSpace
    Delay 0.6
    KeyStrPress BackSpace
    Delay 0.2
    KeyStrRelease BackSpace
    Delay 0.6
    MotionNotify 920 618
    Delay 0.6
    KeyStrPress 3
    Delay 0.1
    KeyStrRelease 3
    Delay 0.6
    MotionNotify 884 661
    Delay 0.6
    ButtonPress 1
    Delay 0.6
    MotionNotify 889 662
    Delay 0.6
    ButtonRelease 1
    Delay 0.6
    MotionNotify 1179 571
    Delay 0.6
    ButtonPress 1
    Delay 0.6
    ButtonRelease 1
    Delay 0.6
    MotionNotify 1060 482
    Delay 0.6
    ButtonPress 1
    Delay 0.6
    ButtonRelease 1

    to add a Delay 108 right up top (this number works for me, ymmv).

  5. while :; do xmacroplay "$DISPLAY" < herp.txt; done; and you can now step safely away. The thing will wake up and do a succession of clicks resulting in the desired craft process being started every almost two minutes. You can chat in game or anything you wish - it's not liable to be bothered or care about you at all.

Nifty, huh ?

———
  1. Totally Massive. Like... I think earlier today there were five people on! At the same time and everything! []
  2. Shift-click takes one out of a stack, ctrl-click takes the whole stack, plain click pops up a number selection dialogue. []
  3. 1300 items! From a previous lucky hit that yielded 1600 of the things in one go! 160`000% returns on that click! []
Category: Trolloludens
Comments feed : RSS 2.0. Leave your own comment below, or send a trackback.

5 Responses

  1. Garfield`s avatar
    1
    Garfield 
    Friday, 10 July 2015

    Hmm, what if the time between actions is somewhat variable? Manually editing times in the macro (and guessing them right) is a pain.

    On Windows one could use Advanced Key and Mouse Recorder. It remembers even cursor movement and key presses, although the latter functionality is unreliable. At any rate it beats any tools I've found for Linux so far ;/

  2. Mircea Popescu`s avatar
    2
    Mircea Popescu 
    Friday, 10 July 2015

    Since the tool simply reads the file on each iteration, you can add a sed to rnd the values in between runs, providing you don't run it VERY often.

    If you're manical you can also get the exact nanosecond time of your clicks by overloading with something like a watcher that writes out the exact timestamp of the file changes.

    Linux wins because Linux is Lego for adults.

  1. [...] To make the line explore method cover a more reasonable area, I used it in combination with an xmacro script that turned my character periodically, and then sent a pilot command to aim him back at the [...]

  2. [...] bot itself is perhaps marginally more useful than the macro previously discussed, but in any case it holds great promise of great things to come. In order to install it and try it [...]

  3. [...] was minding my own business doing other things while my most mircescuesque avatar was busy crafting by itself, when suddenly I was congratulated! For outstanding achievement! Like so [...]

Add your cents! »
    If this is your first comment, it will wait to be approved. This usually takes a few hours. Subsequent comments are not delayed.