基于STM32处理器的USB HID模拟鼠标键盘(2) - 实现键盘鼠标功能

由于在报告描述符中使用了两个Report ID,分别是0x01和0x02,前者是键盘的报告描述符的报告ID,后者是鼠标的报告ID,HID的键盘和鼠标发送的数据格式参考文档:

http://linfengdu.blog.163.com/blog/static/1177107320122296942641/

根据文档编写键盘和鼠标的发送函数如下:

	typedef enum
	{
		KEYBOARD	= 0x01,
		MOUSE		= 0x02,
	}Device;
	
	#define None_Key	0x00
	
	typedef enum
	{
		Left_Control	= 0x01,
		Left_Shift		= 0x02,
		Left_Alt		= 0x04,
		Left_GUI		= 0x08,
		Right_Control	= 0x10,
		Right_Shift		= 0x20,
		Right_Alt		= 0x40,
		Right_GUI		= 0x80,
	}FunctionKey;
	
	typedef enum
	{
		Left_Key		= 0x01,
		Right_Key		= 0x02,
		Mid_Kry			= 0x04,
	}MouseKey;

extern u8 EP1BUSY;
extern u8 HID_SendBuffer[9];

void HID_Send(Device device)
{
	HID_SendBuffer[0] = (u8)device;
	
    /*copy mouse position info in ENDP1 Tx Packet Memory Area*/
    UserToPMABufferCopy(HID_SendBuffer, GetEPTxAddr(ENDP1), 9);
    /* enable endpoint for transmission */
    SetEPTxValid(ENDP1);

	while(EP1BUSY);
	EP1BUSY = 1;

}

void SendKeyboardData(u8 ctrl_shift,u8 key)
{
	HID_SendBuffer[1] = ctrl_shift;
	HID_SendBuffer[3] = key;
	HID_Send(KEYBOARD);
}

void SendMouseData(u8 key,s8 x,s8 y)
{
	HID_SendBuffer[1] = key;
	HID_SendBuffer[2] = (u8)x;
	HID_SendBuffer[3] = (u8)y;
	HID_Send(MOUSE);
}



上一篇:WPF客户端开发需要知道的触摸失效问题


下一篇:使用 avcleaner 对项目进行源码级免杀