May 17, 2015

Linux Keyboard and Mouse Macros

Macros are the simple way to automatize tasks, plus speed. Just record a sequence of keystrokes or mouse moves and clicks in a macro file, and then play it! Here you can see how to record and play a macro in Linux.

The tool used is "XMacro", that as stated in the tool website:

The XMacro package contains two simple, C++ programs (xmacrorec and xmacroplay) for recording and replaying keyboard and mouse events on an X server
So let's start record a macro, with this command:

xmacrorec2 > test.macro

Now you should see something like this:

Server VendorRelease: 11103000
XRecord for server ":0.0" is version 1.13.

Press the key you want to use to end the application. This key can be any key, 
as long as you don't need it while working with the remote display.
A good choice is Escape.

Two things important here, the ":0" is your display number, it will be needed to play your macro. And the stop key to stop the macro recording, as suggested by the tool, just hit Esc to proceed and then Esc again when you want stop the macro recording.

To play the macro, just use this (don't forget to use your display number):

cat test.macro | xmacroplay :0

Now you should see your mouse/keyboard or whatever you recorded, repeating the process. As you will see, the macro speed is very fast, if you want place some delay between the actions, just edit the .macro file and place a delay command line (delay in seconds):

Delay 5   

Below you can see an example where the macro will create a file named "a.txt" with some content using the nano bash editor and then move the terminal window:



That's all!

About the versions
  • xmacrorec2 0.3
  • xmacroplay 0.3
  • Linux Ubuntu 12.04

0 comentários :

Post a Comment