Examples
********

Recorder
========

Record mouse motions
--------------------

Record mouse motions only and save the session to mouse-rec.xnl.

        cnee --record --mouse --out-file mouse-rec.xnl

After having typed this you can move your mouse round for a while. After Xnee has exited you will be able to replay your motions. Xnee will stop after having record 100 events (this is the default behaviour).

Record keyboard
---------------

Record keyboard events only and save log to kbd-rec.xnl.

        cnee --record --keyboard --out-file kbd-rec.xnl

After having typed this Xnee records all your keyboard actions. After Xnee has exited you will be able to replay your keyboard actions. Xnee will stop after having record 100 events (this is the default behaviour).

Record keyboard and mouse
-------------------------

Record keyboard and mouse and save log to km-rec.xnl.

        cnee --record --keyboard --mouse --out-file kbd-rec.xnl

After having typed this Xnee records all your keyboard and mouse actions. So now move your pointer and write some stuff with your keyboard. After Xnee has exited you will be able to replay your keyboard and mouse actions. Xnee will stop after having record 100 events (this is the default behaviour).

Record a gnumeric session
-------------------------

Record a gnumeric session. Record 400 events. Save output in file gnumeric.xnl Start a terminal emulator (e.g xterm)

     xterm&

Start Xnee

        cnee --record --keyboard --mouse --events-to-record 400 \
         --out-file gnumeric.xnl&

Start gnumeric

     gnumeric&

Start using gnumeric. Browse the menus above, reset the fonts etc.

Record a gnumeric session with synchronisation data
---------------------------------------------------

Record a gnumeric session. Record 400 events. Save output in file gnumeric2.xnl

Start a terminal emulator (e.g xterm) xterm&

Start Xnee

        cnee --record --keyboard --mouse --events-to-record 400 \
         --out-file gnumeric2.xnl\
        --delivered-event-range Expose,MapRequest,LeaveNotify,EnterNotify  &

Start gnumeric gnumeric& Start using gnumeric. Browse the menus above, reset the fonts etc.

Replayer
========

Replay mouse motions
--------------------

Replay mouse motions as found in the file mouse-rec.xnl.

        cnee --replay  --file mouse-rec.xnl

Xnee will now imitate exactly what you did when you recorded this file.

Replay mouse motions using with half speed
------------------------------------------

Replay mouse motions as found in the file mouse-rec.xnl but with the speed set to 50% of the recorded.

        cnee --replay  --file mouse-rec.xnl --speed-percent 50

Xnee will now imitate exactly what you did when you recorded this file, allthough it will be done in 50% of the recorded time.

Replay mouse motions using with double speed
--------------------------------------------

Replay mouse motions as found in the file mouse-rec.xnl but with the speed set to 200% of the recorded.

        cnee --replay  --file mouse-rec.xnl --speed-percent 200

Xnee will now imitate exactly what you did when you recorded this file, allthough it will be done twice as fast as when recorded.

Replay keyboard actions
-----------------------

Replay keyboard events from file kbd-rec.xnl.

        cnee --replay --file kbd-rec.xnl

After having typed this Xnee replays all your keyboard actions. After Xnee has exited you will be able to replay your keyboard actions.

Replay keyboard and mouse
-------------------------

Replay keyboard and mouse from the file km-rec.xnl.

        cnee --replay --keyboard --mouse --file kbd-rec.xnl

After having typed this Xnee replays all your keyboard and mouse actions. Xnee moves your pointer and writes the the same stuff as you did when recording.

Replay a gnumeric session
-------------------------

Replay the gnumeric session above Start a terminal emulator (e.g xterm) xterm& Start a new fresh gnumeric spreadsheet gnumeric&

Start Xnee

        cnee --replay  --file gnumeric.xnl

Xnee will now do the same stuff you did when recording. It may happen that some user actions are replayed to early. This is so because Xnee has no way of knowing if it is in sync with the recorded session.

Replay a gnumeric session with synchronisation data
---------------------------------------------------

Replay the second gnumeric session above. Start a terminal emulator (e.g xterm) xterm& Start a new fresh gnumeric spreadsheet gnumeric&

Start Xnee

        cnee --replay  --file gnumeric2.xnl

Xnee will now do the same stuff you did when recording. It may happen that the replaying slows down. This is because Xnee is currently out of sync. When being out of sync Xnee slows down a bit and checks the thresholds if it is allowed to continue. Xnee will most probably find itself in sync after a short while. All recorded user actions should have occured the same way as when recording.

Replay a gnumeric session with synchronisation data setting threshold
---------------------------------------------------------------------

Replay the second gnumeric session above. Start a terminal emulator (e.g xterm) xterm& Start a new fresh gnumeric spreadsheet gnumeric&

Retyper
=======

Retype the help printout
------------------------

If you want Xnee to fake a user typing the help printout from xnee you can use the --type-help option. Start a terminal emulator (e.g xterm) and an editor (e.g emacs).

     xterm &

     emacs &

Retype the help printout by starting xnee with a 10 seconds delay delay.

     cnee --time 10 --type-help

Move your mouse to the editor and make the editor have focus. Wait a few seconds and xnee will type the help. You will now also have a copy of help text.

Retype a file
-------------

If you want Xnee to fake a user typing the letters as found in a text file you can use the retype mode. Note that it isn't possible to retype all characters yet. This will be implemented as soon as possible. We'll give an example on how to use this mode. Start a terminal emulator (e.g xterm)

     xterm &

Create a text file

     echo "Hi Xnee" > testfile.txt

Retype the contents of this file to another file by starting xnee with a 10 seconds delay delay.

     cnee --time 10 --retype-file testfile.txt

Start the fabulous editor cat

     cat > copiedfile.txt

Wait a few seconds and xnee will retype the letters in the file testfile.txt. You will now also have a copy of that file. The copy is called copiedfile.txt. This is a realy a stupid way to copy a file but this option opens up a few possibilities.

Distributor
===========

With the distribution mode Xnee can send your device events to multiple displays.

Distribute your mouse motions
-----------------------------

You can distribute your mouse motions to the displays frodo:0.0 and sam:0.0 Start a terminal emulator (e.g xterm)

     xterm &

Start xnee

     cnee --distribute frodo:0,sam:0.0
      --record --mouse

If you have setup authority correct on frodo and sam you will see all you mouse motions being done on those displays as well.

Distribute the replaying of mouse motions
-----------------------------------------

Replay and distribute mouse motions as found in the file mouse-rec.xnl.

        cnee --replay  --file mouse-rec.xnl
         --distribute frodo:0,sam:0.0

Xnee will now imitate exactly what you did when you recorded this file on your host as well on frodo and sam.

Distribute the retyping of a file
---------------------------------

If you want Xnee to to distribute the fakeing of a user typing the letters as found in a text file you can use the retype mode together with the distribution mode. Start a terminal emulator (e.g xterm) on each of the hosts

     xterm &

Create a text file.

     echo "Hi again Xnee" > distfile.txt

Retype the contents of this file to another file by starting xnee with a 10 seconds delay delay.

     cnee --time 10 --retype-file distfile.txt
      --distribute frodo:0,sam:0.0

Start the fabulous editor cat on the terminal emulators on each the terminals.

     cat > copiedfile.txt

If you have setup authority correct on frodo and sam you will, after a few seconds, see xnee retype the letters in the file distfile.txt. You will now also have three copies of that file. On copy on each host. The copy is called copiedfile.txt. This might seem like a stupid way to copy a file to three locations but this is just an example.

Key
===

Stop Xnee with key
------------------

You can stop xnee by specifying a key. Make sure that this key isn't grabbed by another X client (e.g by the Window Manager). Let's say that you want Xnee to stop recording if you press Control and h.

        cnee --record --mouse --events-to-record -1 --stop-key h

This will make xnee record mouse events until you press h. All printouts are done to stdout so you can see that Xnee stops when you press the key. Move your mouse for a while and you'll see xnee print out lots of lines. Press h. Xnee will now have stopped recording.

Pausing and resuming Xnee with key
----------------------------------

You can pause and resum xnee by specifying a key. Make sure that this key isn't grabbed by another X client (e.g by the Window Manager). Let's say that you want Xnee to pause recording if you press p and to resume when pressing Comntrol and r.

        cnee --record --mouse --events-to-record -1 --pause-key p \
        --resume-key r

This will make xnee record mouse events until you press p. All printouts are done to stdout so you can see that Xnee stops when you press the key. Move your mouse for a while and you'll see xnee print out lots of lines. Press p. Xnee will now have paused recording. Move your mouse for a while and note that nothing is printed. Press r. Xnee will now have resumed recording. Move your mouse for a while and note that xnee begins its printouts.

Using macro
===========

Macors can be used in various applications allthough many applicaions have a macro functionality built in (e.g emacs).

Define a simple macro
---------------------

There are plenty of tools that bind a key combination to different actions. For various reasons the author of this manual is familliar with xrebind so we will use xrebind in this example. The first thing to do is to decide which key combination to tie to the wanted action. Let's say we want to use one of the funtion keys, F1. We then have to find out which keycode belongs to that key. The action we will bind to this key combination will be the replaying of a recorded session from the previous examples. We use Xnee to find the keycode for F1. Start xnee.

        cnee --record --keyboard --events-to-record 20

Press the F1 key and see what number was printed out. It will look something like this:

     0,2,0,0,0,67,0,90300078
     0,3,0,0,0,67,0,90300156

The interesting part here is the 6th column. In our example we find 67, which is the keycode for F1. Now we move on to setup xrebind to grab F1 and bind that to replay the mouse motions from the file mouse-rec.xnl. Open or create a new file in your home directory called .xrbrc and add the lines.

     XrebindGrab
     {
       Action      = Execute
       GrabKeycode = 67
       Modifier    = AnyModifier
       Command     = xnee  --replay --file mouse-rec.xnl
       Comment     = Starting xnee replay
       AutoRepeat  = false
       Fork        = true
     }

Let's try it. Start xrebind with verbose printouts.

     xrebind --verbose

Press F1 and the recorded session from the previous example shall be replayed. You can also see in the verbose printouts that xrebind executes xnee.

Define another simple macro
---------------------------

Let's say we want to bind Control and e to execute the session as in the example above. This time setting up xrebind is a bit easier. Setup xrebind to grab F1 and bind that to replay the mouse motions from the file mouse-rec.xnl by opening or create a new file in your home directory called .xrbrc and add the lines.

     XrebindGrab
     {
       Action      = Execute
       GrabKey     = e
       Modifier    = Control
       Command     = xnee  --replay --file mouse-rec.xnl
       Comment     = Starting xnee replay
       AutoRepeat  = false
       Fork        = true
     }
     e, Control, Exec, xnee,  --replay --file mouse-rec.xnl, \
     Fork, NoAutoRepeat

Let's try it. Start xrebind with verbose printouts.

     xrebind --verbose

Press Control and e and the recorded session from the previous example shall be replayed.

Various options
===============

Using verbose mode
------------------

To enable verbose mode, start xnee like this

     cnee --verbose --record --mouse

Move the mouse for a while and you'll lots of verbose printouts that usualy isn't there.

Using human readable printouts
------------------------------

To enable human printout mode, start xnee like this

     cnee --human-printout --record --mouse

Move the mouse for a while and you'll see the data printed out in an almost human friendly format.

Using a differet screen resolution
----------------------------------

If a session was recorded on a screen with another resolution than on the one where we replay the session xnee will translate all coordinates automagically. However, you can force xnee to use a specific resolution when replaying. To do this, start xnee like this

     cnee --replay --file mouse-rec.xnl \
     --replay-resolution  800x600

Xnee will now replay the events recorded in the sessions file mouse-rec.xnl as if the screen has a resolution of 800x600.

Using a offset when replaying
-----------------------------

If a session was recording a centered window with a window manager and is to bo replayed without a window manager (still centered) you can use the offset switch to make Xnee replay the events in order to get the coordinates right.

     cnee --replay --file mouse-rec.xnl \
     --replay-offset 12,-7

Xnee will now replay the events recorded in the sessions file mouse-rec.xnl and adding 12 to the x coordinate and subtract 7 from the y coordinate.

Using a window position recall
------------------------------

For some reason a replayed window may pop up at a different position as when recorded. Xnee can try to solve this by adding the recall-window-position option during replay.

     cnee --replay --file mouse-rec.xnl \
     --recall-window-position

If a window pops up at a different position when replaying (as whe recorded) Xnee moves the new window to the same position as when recorded.

Using no resolution translation
-------------------------------

If a session was recorded on a screen with another resolution than the on the one where we replay the session xnee will translate all coordinates automagically. However, you can force xnee not to use translation. To do this, start xnee like this

     cnee --replay --file mouse-rec.xnl \
     --no-resolution-adjustment

Xnee will now replay the events recorded in the sessions file mouse-rec.xnl as if the screen had the same resolution the recorded one.

Record another display than the default
---------------------------------------

If you want to record another display than the default, as set in the DISPLAY variable, you use the --display option.

     cnee --record --mouse --display frodo:0.0

Xnee will now record the mouse events on the display frodo:0.0.

Replay to another display than the default
------------------------------------------

If you want to replay to another display than the default, as set in the DISPLAY variable, you use the --display option.

     cnee --replay --display frodo:0.0 --file mouse-rec.xnl

Xnee will now replay the mouse events on the display frodo:0.0.

Shell scripts using Xnee
========================

Insted of onvoking Xnee for every time you need to fake events you can make use of the shell functions as delivered with Xnee. With these functions you can start one instance of Xnee and fake device events whenever you need.

     #!/bin/bash

     # Source in handy functions
     . /usr/share/xnee/xnee.sh

     # Loop and press buttons
     TMP=0
     while [ $TMP -le 5]
     do
       TMP=$(($TMP+1))
       xnee_fake_button $TMP
     done

     # Just a simple example ....don't bother to understand
     tar cvf /tmp/crap.tar *
     sleep 2

     # Fake ls and Enter
     xnee_fake_key l
     xnee_fake_key s
     xnee_fake_key XK_Return

This example will fake press and release of the mouse button and do fake press and release of ls followed by a press and release of Enter.... and of course, you'll get a tar file in /tmp.

Make sure that the path to the xnee.sh is correct.