model_server/em/src/em.cxx
/*_______________________________________________________________________
!
! Function:	em_send_event & em_send_detailed_event
!
! Arguments:	Window win
!		int event
!		unsigned int modifiers 
!		     Bit wise OR the following modifiers for held
!		     down keys:
!	     		Shift	0x0001
!	     		Lock	0x0002	
!	     		Control	0x0004	
!	     		Mod1	0x0008	(Alt or Meta)	
!	     		Mod2	0x0010	
!	     		Mod3	0x0020	
!	     		Mod4	0x0040
!	     		Mod5	0x0080
!		int mouse_button	between 1 and 3
!       
! Returns:	void
!
! Synopsis:	Passes each character in the string as an event to the 
!			passed window.		
!
_______________________________________________________________________*/


Window win
int event
unsigned int modifiers
Bit wise OR the following modifiers for held
down keys:
Shift   0x0001
Lock    0x0002
Control 0x0004
Mod1    0x0008  (Alt or Meta)
Mod2    0x0010
Mod3    0x0020
Mod4    0x0040
Mod5    0x0080
int mouse_button        between 1 and 3

void

Passes each character in the string as an event to the
passed window.


Window win int event unsigned int modifiers Bit wise OR the following modifiers for held down keys : Shift 0x0001 Lock 0x0002 Control 0x0004 Mod1 0x0008 ( Alt or Meta ) Mod2 0x0010 Mod3 0x0020 Mod4 0x0040 Mod5 0x0080 int mouse_button between 1 and 3 void Passes each character in the string as an event to the passed window .
void em_send_detailed_event (Window win, int event, 
			     unsigned int modifiers = 0, 
			     int mouse_button = 1)
{
    Initialize(em_send_detailed_event);
    XEvent ev;
    OS_dependent::bzero((char*)&ev, sizeof(XEvent));
    if (!win) return;
    if (mouse_button < 1) 
	mouse_button = 1;
    if (mouse_button > 3) 
	mouse_button = 3;
    int button_number;
    switch(mouse_button) {
      case 1:
	button_number = Button1;
	break;
      case 2:
	button_number = Button2;
	break;
      case 3:
	button_number = Button3;
	break;
      case 4:
	button_number = Button4;
	break;
      case 5:
	button_number = Button5;
	break;
      default:
	button_number = Button1;
	break;
    }
    struct timeval time_values;
    struct timezone time_zones;
    OSapi_gettimeofday(&time_values, &time_zones);
    if (starttime == 0)
	starttime = time_values.tv_sec - 10;
    unsigned long timestamp = (time_values.tv_sec - starttime) * 1000 +
	(time_values.tv_usec / 1000);  
    Window root, child;
    int rootx, rooty, x, y;
    unsigned int but;
    XQueryPointer (UxDisplay, win, &root, &child,
		   &rootx, &rooty, &x, &y, &but);
    switch (event) {
    case PUSH:
	ev.xbutton.type = ButtonPress;
        ev.xbutton.serial = 0;
        ev.xbutton.send_event = FALSE;
        ev.xbutton.display = UxDisplay;
        ev.xbutton.window = win;
        ev.xbutton.root = win;
        ev.xbutton.subwindow = child;
        ev.xbutton.time = timestamp;
        ev.xbutton.x = x;
        ev.xbutton.y = y;
        ev.xbutton.x_root = rootx;
        ev.xbutton.y_root = rooty;
        ev.xbutton.state = modifiers;
  	ev.xbutton.button =  button_number;
        ev.xbutton.same_screen = True;
	XSendEvent (UxDisplay, win, True, 0, &ev);
	OS_dependent::usleep(100000);
	break;
    case RELEASE:
	ev.xbutton.type = ButtonRelease;
        ev.xbutton.serial = 0;
        ev.xbutton.send_event = FALSE;
        ev.xbutton.display = UxDisplay;
        ev.xbutton.window = win;
        ev.xbutton.root = win;
        ev.xbutton.subwindow = child;
        ev.xbutton.time = timestamp;
        ev.xbutton.x = x;
        ev.xbutton.y = y;
        ev.xbutton.x_root = rootx;
        ev.xbutton.y_root = rooty;
        ev.xbutton.state = modifiers;
  	ev.xbutton.button =  button_number;
        ev.xbutton.same_screen = True;
	XSendEvent (UxDisplay, win, True, 0, &ev);
	OS_dependent::usleep(100000);
	break;
    case CLICK:
        em_send_detailed_event (win, PUSH, modifiers, mouse_button);
        em_send_detailed_event (win, RELEASE, modifiers, mouse_button);
	break;
    }
}
void em_send_detailed_event ( Window win , int event , unsigned int modifiers = 0 , int mouse_button = 1 ) { Initialize ( em_send_detailed_event ) ; XEvent ev ; OS_dependent :: bzero ( ( char * ) & ev , sizeof ( XEvent ) ) ; if ( ! win ) return ; if ( mouse_button < 1 ) mouse_button = 1 ; if ( mouse_button > 3 ) mouse_button = 3 ; int button_number ; switch ( mouse_button ) { case 1 : button_number = Button1 ; break ; case 2 : button_number = Button2 ; break ; case 3 : button_number = Button3 ; break ; case 4 : button_number = Button4 ; break ; case 5 : button_number = Button5 ; break ; default : button_number = Button1 ; break ; } struct timeval time_values ; struct timezone time_zones ; OSapi_gettimeofday ( & time_values , & time_zones ) ; if ( starttime == 0 ) starttime = time_values . tv_sec - 10 ; unsigned long timestamp = ( time_values . tv_sec - starttime ) * 1000 + ( time_values . tv_usec / 1000 ) ; Window root , child ; int rootx , rooty , x , y ; unsigned int but ; XQueryPointer ( UxDisplay , win , & root , & child , & rootx , & rooty , & x , & y , & but ) ; switch ( event ) { case PUSH : ev . xbutton . type = ButtonPress ; ev . xbutton . serial = 0 ; ev . xbutton . send_event = FALSE ; ev . xbutton . display = UxDisplay ; ev . xbutton . window = win ; ev . xbutton . root = win ; ev . xbutton . subwindow = child ; ev . xbutton . time = timestamp ; ev . xbutton . x = x ; ev . xbutton . y = y ; ev . xbutton . x_root = rootx ; ev . xbutton . y_root = rooty ; ev . xbutton . state = modifiers ; ev . xbutton . button = button_number ; ev . xbutton . same_screen = True ; XSendEvent ( UxDisplay , win , True , 0 , & ev ) ; OS_dependent :: usleep ( 100000 ) ; break ; case RELEASE : ev . xbutton . type = ButtonRelease ; ev . xbutton . serial = 0 ; ev . xbutton . send_event = FALSE ; ev . xbutton . display = UxDisplay ; ev . xbutton . window = win ; ev . xbutton . root = win ; ev . xbutton . subwindow = child ; ev . xbutton . time = timestamp ; ev . xbutton . x = x ; ev . xbutton . y = y ; ev . xbutton . x_root = rootx ; ev . xbutton . y_root = rooty ; ev . xbutton . state = modifiers ; ev . xbutton . button = button_number ; ev . xbutton . same_screen = True ; XSendEvent ( UxDisplay , win , True , 0 , & ev ) ; OS_dependent :: usleep ( 100000 ) ; break ; case CLICK : em_send_detailed_event ( win , PUSH , modifiers , mouse_button ) ; em_send_detailed_event ( win , RELEASE , modifiers , mouse_button ) ; break ; } }
_______________________________________________________________________
Function:      em_send_event & em_send_detailed_event
_______________________________________________________________________ Function : em_send_event & em_send_detailed_event
/* Construct an artifical timestamp in microseconds. */ /* timestamp in milliseconds */ /* Get the cursor position. */