You can't just write to the device file and expect the drivers to behave as if actual hardware was sending these events. Things are way more complicated than that.
If you are only concerned with X Windows environment you are in luck. You can use this function to send events to the window:
http://tronche.com/gui/x/xlib/event-handling/XSendEvent.html
If you don't know which window should be receiving your events just send them to the root window, they will be routed appropriately.
Also there is a library for that.
http://www.x.org/releases/X11R7.6/doc/libXtst/recordlib.html
Just keep in mind that in X windows events have a flag that indicates whether the event came from the actual hardware or was synthesized by one of the above methods. In most cases programs just ignore this flag and behave the same regardless. But sometimes you can have weird surprises.