Xlib programming - Emulating left click press/released

Hi,

Lately my university asked me to develop an application to be installed on some computers for the disabled. I've developed a head tracking software (it moves the cursor on the screen following your head's movements using a webcam), and it works greatly so far except for a missing feature. I'm going to interpret a forward movement of the head (towards the cam) as a left button click, and the left button is released when the head moves back. So far I can recognize these events, but I don't know how to emulate a mouse event (left button clicked/released) using Xlib. I've tried several functions, XGrabButton as well as XSetPointerMapping, but none of them seems to fit my purpose (and there's really not much documentation about these online).

Does anyone know how I can fix this problem?

Have you tried xdotool - it simulates mouse and keyboard events -
xdotool - fake keyboard/mouse input :: semicomplete.com - Jordan Sissel

Thanks for your reply. Anyway I was looking for a code solution, not for an external tool...
I found a solution yesterday night anyway, using XTestFakeButtonEvent function in Xlib extension, and it seems to work greatly for my purpose ^^