⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xtest1dd.c

📁 远程桌面连接工具
💻 C
📖 第 1 页 / 共 3 页
字号:
		 */		flush_input_actions();	}}	/****************************************************************************** * *	current_ms * *	Returns the number of milliseconds from the passed-in time to the *	current time, and then updates the passed-in time to the current time. */static CARD32current_ms(otime)struct timeval	*otime;{		struct timeval	tval;	unsigned long	the_ms;	unsigned long	sec;	unsigned long	usec;	/*	 * get the current time	 */	X_GETTIMEOFDAY(&tval);	if (tval.tv_usec < otime->tv_usec)	{		/*		 * borrow a second's worth of microseconds if needed		 */		usec = tval.tv_usec - otime->tv_usec + 1000000;		sec = tval.tv_sec - 1 - otime->tv_sec;	}	else	{		usec = tval.tv_usec - otime->tv_usec;		sec = tval.tv_sec - otime->tv_sec;	}	/*	 * update the passed-in time to the new time	 */	*otime = tval;	/*	 * compute the number of milliseconds contained in	 * 'sec' seconds and 'usec' microseconds	 */	the_ms = (sec * 1000000L + usec) / 1000L;	return (the_ms);}/****************************************************************************** * *	check_time_event * *	If time delta is > XTestSHORT_DELAY_TIME then insert a time event *	and return 0; else return the delay time. */static CARD16check_time_event(){	CARD32		tstamp;	CARD16		tchar;	XTestDelayInfo	*tptr;	/*	 * get the number of milliseconds between input actions	 */	tstamp = current_ms(&current_time);	/*	 * if the number of milliseconds is too large to fit in a CARD16,	 * then add a XTestDELAY_ACTION to the input action event.	 */	if (tstamp > XTestSHORT_DELAY_TIME)	{		/*		 * If there isn't room in the input action event for		 * an XTestDELAY_ACTION, then send that event to the		 * client and start filling an empty one.		 */		if (!there_is_room(sizeof(XTestDelayInfo)))		{			flush_input_actions();		}		/*		 * point tptr to the correct place in the input action event		 */		tptr = (XTestDelayInfo *)		       (&(input_action_packet.actions[packet_index]));		/*		 * compute the input action header		 */		tptr->header = XTestPackDeviceID(XTestDELAY_DEVICE_ID) |			       XTestDELAY_ACTION;		/*		 * set the delay time in the input action		 */		tptr->delay_time = tstamp;		/*		 * increment the packet index by the size of the input action		 */		packet_index = packet_index + (sizeof(XTestDelayInfo));		if (packed_mode != XTestPACKED_ACTIONS) 		{			/*			 * if input actions are not packed, send the input			 * action event to the client			 */			flush_input_actions();		}		/*		 * set the returned delay time to 0		 */		tchar = 0;	}	else	{		/*		 * set the returned delay time to the computed delay time		 */		tchar = tstamp;	}	return(tchar);}/****************************************************************************** * *	there_is_room * *	Checks if there is room in the input_action_packet for an input action *	of the size actsize bytes.  Returns 1 if there is space, 0 otherwise. * */static intthere_is_room(actsize)/* * the number of bytes of space needed */int	actsize;{	if ((packet_index + actsize) > XTestACTIONS_SIZE)	{ 		input_action_event_full = 1;		return(0);	}	else	{		return(1);	}}/****************************************************************************** * *	XTestStealMotionData * *	Put motion information from the locator into an input action. * *	called from x_hil.c */voidXTestStealMotionData(dx, dy, dev_type, mx, my)/* * the x and y delta motion of the locator */short	dx;short	dy;/* * which locator did the moving */int	dev_type;/* * the x and y position of the locator before the delta motion */short	mx;short	my;{	/*	 * pointer to a XTestMOTION_ACTION input action	 */	XTestMotionInfo	*fm;	/*	 * time delta from previous event	 */	CARD16			tchar;	/*	 * if the current position of the locator is not the same as	 * the logical position, then update the logical position	 */	if ((mx != xtest_mousex) || (my != xtest_mousey))	{		XTestStealJumpData(mx, my, dev_type);	}	/*	 * if the delta motion is outside the range that can	 * be held in a motion input action, use a jump input action	 */	if ((dx > XTestMOTION_MAX) || (dx < XTestMOTION_MIN) ||	    (dy > XTestMOTION_MAX) || (dy < XTestMOTION_MIN))	{		XTestStealJumpData((xtest_mousex + dx),				   (xtest_mousey + dy), dev_type);	}	else	{ 		/*		 * compute the new logical position of the mouse		 */		xtest_mousex += dx;		xtest_mousey += dy;		/*		 * Get the time delta from the previous event.  If needed,		 * the check_time_event routine will put an XTestDELAY_ACTION		 * type action in the input action event.		 */		tchar = check_time_event();		/*		 * If there isn't room in the input action event for		 * an XTestDELAY_ACTION, then send that event to the		 * client and start filling an empty one.		 */		if (!there_is_room(sizeof(XTestMotionInfo)))		{			flush_input_actions();		/*		 * point fm to the correct place in the input action event		 */		}		fm = (XTestMotionInfo *)		     &(input_action_packet.actions[packet_index]);		/*		 * compute the input action header		 */		fm->header = XTestMOTION_ACTION;		if (dx < 0)			{  			fm->header |= XTestX_NEGATIVE;			dx = abs(dx);		}		if (dy < 0)   		{  			fm->header |= XTestY_NEGATIVE;			dy = abs(dy);		}		fm->header |= XTestPackDeviceID(dev_type);		/*		 * compute the motion data byte		 */		fm->motion_data = XTestPackYMotionValue(dy);		fm->motion_data |= XTestPackXMotionValue(dx);		/*		 * set the delay time in the input action		 */		fm->delay_time = tchar;		/*		 * increment the packet index by the size of the input action		 */		packet_index = packet_index + sizeof(XTestMotionInfo);		if (packed_mode == 0)		{			/*			 * if input actions are not packed, send the input			 * action event to the client			 */			flush_input_actions();		}	}   }/****************************************************************************** * *	XTestStealKeyData * * 	Place this key data in the input_action_packet. * */BoolXTestStealKeyData(keycode, keystate, dev_type, locx, locy)/* * which key/button moved */CARD8	keycode;/* * whether the key/button was pressed or released */char	keystate;/* * which device caused the input action */int	dev_type;/* * the x and y coordinates of the locator when the action happenned */short	locx;short	locy;{	/*	 * pointer to key/button motion input action	 */	XTestKeyInfo	*kp;	/*	 * time delta from previous event	 */	CARD16			tchar;	char		keytrans;	/*	 * update the logical position of the locator if the physical position	 * of the locator is not the same as the logical position.	 */	if ((locx != xtest_mousex) || (locy != xtest_mousey))	{		XTestStealJumpData(locx, locy, dev_type);	}	/*	 * Get the time delta from the previous event.  If needed,	 * the check_time_event routine will put an XTestDELAY_ACTION	 * type action in the input action event.	 */	tchar = check_time_event();	if (!there_is_room(sizeof(XTestKeyInfo)))	{		/*		 * If there isn't room in the input action event for		 * an XTestDELAY_ACTION, then send that event to the		 * client and start filling an empty one.		 */		flush_input_actions();	}	/*	 * point kp to the correct place in the input action event	 */	kp = (XTestKeyInfo *)	     (&(input_action_packet.actions[packet_index]));	/*	 * compute the input action header	 */	kp->header = XTestPackDeviceID(dev_type);	if ((keystate == KeyRelease) || (keystate == ButtonRelease))	{		keytrans = XTestKEY_UP;	}	else if ((keystate == KeyPress) || (keystate == ButtonPress))	{		keytrans = XTestKEY_DOWN;	}	else	{		printf("%s: invalid key/button state %d.\n",		       XTestEXTENSION_NAME,		       keystate);	}	kp->header = kp->header | keytrans | XTestKEY_ACTION;	/*	 * set the keycode in the input action	 */	kp->keycode = keycode;	/*	 * set the delay time in the input action	 */	kp->delay_time = tchar;	/*	 * increment the packet index by the size of the input action	 */	packet_index = packet_index + sizeof(XTestKeyInfo);	/*	 * if the command key has been released or input actions are not	 * packed, send the input action event to the client	 */ 	if(((keycode == xtest_command_key) && (keystate == KeyRelease)) ||	   (packed_mode != XTestPACKED_ACTIONS))	{			flush_input_actions();	}	/* return TRUE if the event should be passed on to DIX */	if (exclusive_steal)		return ((keystate == KeyRelease) &&			(keycode == xtest_command_key));	else		return ((keystate != KeyRelease) ||			(keycode != xtest_command_key));}/****************************************************************************** * *	parse_fake_input * *	Parsing routine for a XTestFakeInput request.  It will take a request *	and parse its contents into the input action array.  Eventually the *	XTestProcessInputAction routine will be called to take input actions *	from the input action array and send them to the server to be handled. */voidparse_fake_input(client, req)/* * which client did the XTestFakeInput request */ClientPtr	client;/* * a pointer to the xTestFakeInputReq structure sent by the client */char		*req;{		/*	 * if set to 1, done processing input actions from the request	 */	int	        	done = 0;	/*	 * type of input action	 */	CARD8			action_type;	/*	 * device type	 */	CARD8			dev_type;	/*	 * pointer to an xTestFakeInputReq structure	 */	xTestFakeInputReq	*request;	/*	 * holds the index into the action list in the request	 */	int			parse_index;		/*	 * get a correct-type pointer to the client-supplied request data	 */	request = (xTestFakeInputReq *) req;	/*	 * save the acknowledge requested state for use in	 * XTestProcessInputAction	 */	acknowledge = request->ack;	/*	 * set up an index into the action list in the request	 */	parse_index = 0;	if (write_index >= ACTION_ARRAY_SIZE)	{		/*		 * if the input action array is full, don't add any more		 */		done = 1;	}	while (!done)	{ 		/*		 * get the type of input action in the list		 */		action_type = (request->action_list[parse_index])			      & XTestACTION_TYPE_MASK;		/*		 * get the type of device in the list		 */		dev_type = XTestUnpackDeviceID(request->action_list[parse_index]);		/*		 * process the input action appropriately		 */		switch (action_type)		{ 		case XTestKEY_ACTION:			parse_key_fake((XTestKeyInfo *)				       &(request->action_list[parse_index]));			parse_index = parse_index + sizeof(XTestKeyInfo);			break;		case XTestMOTION_ACTION:			parse_motion_fake((XTestMotionInfo *)					  &(request->action_list[parse_index]));			parse_index = parse_index + sizeof(XTestMotionInfo);			break;		case XTestJUMP_ACTION:			parse_jump_fake((XTestJumpInfo *)					&(request->action_list[parse_index]));			parse_index = parse_index + sizeof(XTestJumpInfo);			break;		case XTestDELAY_ACTION:			if (dev_type == XTestDELAY_DEVICE_ID)			{ 				parse_delay_fake((XTestDelayInfo *)						 &(request->action_list[parse_index]));				parse_index = parse_index +					      sizeof(XTestDelayInfo);			}			else			{ 				/*				 * An invalid input action header byte has				 * been detected, so there are no more				 * input actions in this request.				 * The intended invalid action header byte				 * for this case should have a value of 0.				 */				done = 1;			}			break;		}		if (parse_index >= XTestMAX_ACTION_LIST_SIZE)		{			/*			 * entire XTestFakeInput request has been processed			 */			done = 1;		}		if (write_index >= ACTION_ARRAY_SIZE) 		{			/*			 * no room in the input actions array			 */			done = 1;		}	}	if (write_index > read_index)	{ 		/*		 * there are fake input actions in the input action array		 * to be given to the server		 */		playback_on = 1;		playback_client = client;	} }/****************************************************************************** * *	parse_key_fake * *	Called from parse_fake_input. * *	Copy the fake key input action from its packed form into the array of *	pending input events. */static voidparse_key_fake(fkey)XTestKeyInfo	*fkey;{		action_array[write_index].type = XTestKEY_ACTION;	action_array[write_index].device = XTestUnpackDeviceID(fkey->header);	action_array[write_index].keycode = fkey->keycode;	action_array[write_index].keystate = fkey->header & XTestKEY_STATE_MASK;	action_array[write_index].delay_time = fkey->delay_time;	write_index++;}/****************************************************************************** * *	parse_motion_fake * *	Called from parse_fake_input. * *	Copy the fake motion input action from its packed form into the array of *	pending input events. */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -