How to emit mouse events

Hello everyone!
I want to write a routine to simulate the mouse motion,and I do as
following:
The purpose of this routine is to press mouse right_button at (200,200),
where an window can be brought to front(focused). Actually, it does not
workd! What’s the reason?

main()
{
PhEvent_t event;
PhRect_t rect;
PhRawPtrEvent_t ptr_event;
iov_t mx[4];


if( NULL == PhAttach( NULL, NULL ) )
{
exit( EXIT_FAILURE );
}

event.type = Ph_EV_RAW ;
event.subtype = Ph_EV_RAW_PTR ;
event.collector.rid = Ph_ROOT_RID ;
event.emitter.rid = Ph_DEV_RID ;
event.input_group = PhInputGroup(NULL) ;
event.flags = 0 ;
event.num_rects = 1;
event.data_len = sizeof( ptr_event );

rect.ul.x = rect.lr.x = 100 ;
rect.ul.y = rect.lr.y = 600;

ptr_event.coord[1].x = 200 ;
ptr_event.coord[1].y = 200 ;

ptr_event.flags = 0 ;
ptr_event.num_coord = 2 ;
ptr_event.button_state = Ph_BUTTON_SELECT;

SETIOV( &mx[3], &ptr_event, sizeof( ptr_event ) );
if( PhEventEmitmx( &event, &rect, 4, mx ) < 0)
{
printf(“Raw Ptr Event Emit Error!\n”) ;
}
else
printf(“Raw Ptr Event Emit Sucess!\n”) ;
}