虚拟键盘鼠标UVKM测试示例
2023-06-12
340
0
为了模拟键盘按键的点击延迟效果,这里我们再次进行一次延迟封装。
VOID CUVKMDlg::SendHidReport(PVOID pData, ULONG nLen, ULONG Count, ULONG ms)
{
CHid hid;
if (hid.OpenHid())
{
for (int i = 0; i < Count; i++)
{
Sleep(ms);
hid.SetReport(pData, nLen);
}
}
hid.CloseHid();
}
键盘测试示例
void CUVKMDlg::OnBnClickedKeyboard()
{
KEYBOARD_STRUCT k;
memset(&k, 0, sizeof(k));
Sleep(1000);
for (int i = 0; i < 100; i++)
{
k.ReportId = 0xa1;
k.Key[0] = 0x04 + i % 36;
SendHidReport(&k, sizeof(k), 1, 5);
k.Key[0] = 0x00;
SendHidReport(&k, sizeof(k), 1, 5);
}
memset(&k, 0, sizeof(k));
SendHidReport(&k, sizeof(k), 1, 10);
}
全局鼠标测试
void CUVKMDlg::OnBnClickedGlobalMouseLeftClick()
{
int nWidth = GetSystemMetrics(SM_CXSCREEN);
int nHeight = GetSystemMetrics(SM_CYSCREEN);
GMOUSE_STRUCT m;
memset(&m, 0, sizeof(m));
m.ReportId = 0xA2;
m.btn.u.LeftBtn = 1;
m.X = GetDlgItemInt(IDC_EDIT_GLOBAL_MOUSE_X) * 32767 / nWidth;
m.Y = GetDlgItemInt(IDC_EDIT_GLOBAL_MOUSE_Y) * 32767 / nHeight;
SendHidReport(&m, sizeof(m), 1, 1000);
m.btn.u.LeftBtn = 0;
SendHidReport(&m, sizeof(m), 1, 10);
}
void CUVKMDlg::OnBnClickedGlobalMouseRightClick()
{
int nWidth = GetSystemMetrics(SM_CXSCREEN);
int nHeight = GetSystemMetrics(SM_CYSCREEN);
GMOUSE_STRUCT m;
memset(&m, 0, sizeof(m));
m.ReportId = 0xA2;
m.btn.u.RightBtn = 1;
m.X = GetDlgItemInt(IDC_EDIT_GLOBAL_MOUSE_X) * 32767 / nWidth;
m.Y = GetDlgItemInt(IDC_EDIT_GLOBAL_MOUSE_Y) * 32767 / nHeight;
SendHidReport(&m, sizeof(m), 1, 1000);
m.btn.u.RightBtn = 0;
SendHidReport(&m, sizeof(m), 1, 10);
}
普通鼠标测试
void CUVKMDlg::OnBnClickedMouseUp()
{
MOUSE_STRUCT m;
memset(&m, 0, sizeof(m));
m.ReportId = 0xa0;
m.Veritical = -1;
SendHidReport(&m, sizeof(m), 100, 10);
}
void CUVKMDlg::OnBnClickedMouseDown()
{
MOUSE_STRUCT m;
memset(&m, 0, sizeof(m));
m.ReportId = 0xa0;
m.Veritical = 1;
SendHidReport(&m, sizeof(m), 100, 10);
}
void CUVKMDlg::OnBnClickedMouseLeft()
{
MOUSE_STRUCT m;
memset(&m, 0, sizeof(m));
m.ReportId = 0xa0;
m.Horizontal = -1;
SendHidReport(&m, sizeof(m), 100, 10);
}
void CUVKMDlg::OnBnClickedMouseRight()
{
MOUSE_STRUCT m;
memset(&m, 0, sizeof(m));
m.ReportId = 0xa0;
m.Horizontal = 1;
SendHidReport(&m, sizeof(m), 100, 10);
}
void CUVKMDlg::OnBnClickedMouseLeftClick()
{
MOUSE_STRUCT m;
memset(&m, 0, sizeof(m));
m.ReportId = 0xa0;
m.btn.u.LeftBtn = 1;
SendHidReport(&m, sizeof(m), 1, 1000);
m.btn.u.LeftBtn = 0;
SendHidReport(&m, sizeof(m), 1, 1000);
}
void CUVKMDlg::OnBnClickedMouseRightClick()
{
MOUSE_STRUCT m;
memset(&m, 0, sizeof(m));
m.ReportId = 0xa0;
m.btn.u.RightBtn = 1;
SendHidReport(&m, sizeof(m), 1, 1000);
m.btn.u.RightBtn = 0;
SendHidReport(&m, sizeof(m), 1, 1000);
}
void CUVKMDlg::OnBnClickedMouseWheelUp()
{
MOUSE_STRUCT m;
memset(&m, 0, sizeof(m));
m.ReportId = 0xa0;
m.Wheel = -1;
SendHidReport(&m, sizeof(m), 30, 10);
}
void CUVKMDlg::OnBnClickedMouseWheelDown()
{
MOUSE_STRUCT m;
memset(&m, 0, sizeof(m));
m.ReportId = 0xa0;
m.Wheel = 1;
SendHidReport(&m, sizeof(m), 30, 10);
}
HID人机交互QQ群:564808376
UAC音频QQ群:218581009
UVC相机QQ群:331552032
BOT&UASP大容量存储QQ群:258159197
STC-USB单片机QQ群:315457461
USB技术交流QQ群2:580684376
USB技术交流QQ群:952873936