请问鼠标精灵怎么用(鼠标精灵电脑版)

懵懂先生 投稿文章请问鼠标精灵怎么用(鼠标精灵电脑版)已关闭评论54阅读模式

文章源自略懂百科-http://wswcn.cn/107840.html

欢迎大家提意见,不断改进文章源自略懂百科-http://wswcn.cn/107840.html

基于上一篇的鼠标记程器的框架和知识,这次实现一个简单的鼠标按键精灵。按键精灵类软件经常被用在游戏外挂和程序界面的自动化测试,模拟控制鼠标、键盘、外部设备的状态,通过执行提前录制好的规则、脚本来则可以实现批量处理。文章源自略懂百科-http://wswcn.cn/107840.html

整个程序比较简单,实现方式如下:文章源自略懂百科-http://wswcn.cn/107840.html

1、首先创建对话框和对话框上的控件,然后就是注册热键,因为一旦鼠标自动点击开始,就只能通过键盘组合键来让整个过程停止。特别要注意的是,注册的热键尽量不要和其它程序注册的一样,否则会冲突,冲突后可能会失效,因此注册的越特殊越好。文章源自略懂百科-http://wswcn.cn/107840.html

这里注册了2组热键,CTRL+SHIFT+F4用来锁定或释放鼠标的位置,CTRL+SHIFT+F6用来停止鼠标自动点击的过程。注册的热键要在程序退出时主动调用UnregisterHotKey删除掉。文章源自略懂百科-http://wswcn.cn/107840.html

RegisterHotKey(hWndDlg, WM_MOUSE_POS, MOD_CONTROL | MOD_SHIFT, VK_F4);文章源自略懂百科-http://wswcn.cn/107840.html

RegisterHotKey(hWndDlg, WM_MOUSE_STOP, MOD_CONTROL | MOD_SHIFT, VK_F6);文章源自略懂百科-http://wswcn.cn/107840.html

2、这里使用CreateDialogParam创建非模式对话框,制定自己的消息循环,非模式对话框可以正常接收键盘、鼠标消息。文章源自略懂百科-http://wswcn.cn/107840.html

3、消息及逻辑处理文章源自略懂百科-http://wswcn.cn/107840.html

程序启动过后,首先创建定时器,用来实时获取鼠标的位置。处理热键文章源自略懂百科-http://wswcn.cn/107840.html

热键的消息处理逻辑文章源自略懂百科-http://wswcn.cn/107840.html

3、启动按钮处理,启动定时器开始模拟鼠标点击,开始和结束时间的逻辑比较简单暂时没有实现。文章源自略懂百科-http://wswcn.cn/107840.html

通过mouse_event实现模拟鼠标点击,但杀软、防火墙、部分游戏则可能屏蔽mouse_event。这些程序一般会挂接钩子或采用驱动,识别消息到底是不是由外部真正的键盘和鼠标产生的,如果不是会丢弃掉,主要是为了防止记录键盘和鼠标的木马程序。文章源自略懂百科-http://wswcn.cn/107840.html

完整的程序代码如下:文章源自略懂百科-http://wswcn.cn/107840.html

define WM_MOUSE_POS WM_USER + 100文章源自略懂百科-http://wswcn.cn/107840.html

define WM_MOUSE_STOP WM_USER + 100文章源自略懂百科-http://wswcn.cn/107840.html

define ID_TIMER_MOUSE 1文章源自略懂百科-http://wswcn.cn/107840.html

define ID_TIMER_CLICK 2文章源自略懂百科-http://wswcn.cn/107840.html

BOOL CALLBACK WndDlg(HWND,UINT,WPARAM,LPARAM);文章源自略懂百科-http://wswcn.cn/107840.html

BOOL CALLBACK AboutDlg(HWND,UINT,WPARAM,LPARAM);文章源自略懂百科-http://wswcn.cn/107840.html

HINSTANCE hInst;文章源自略懂百科-http://wswcn.cn/107840.html

POINT g_mousePos = { 0, 0 };文章源自略懂百科-http://wswcn.cn/107840.html

bool g_lockMouse = false;文章源自略懂百科-http://wswcn.cn/107840.html

SYSTEMTIME g_startSt = { 0 }, g_endSt = { 0 };文章源自略懂百科-http://wswcn.cn/107840.html

int g_clickType = 0; //0表示单击,1表示双击文章源自略懂百科-http://wswcn.cn/107840.html

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR lpCmdLine, int nShowCmd)文章源自略懂百科-http://wswcn.cn/107840.html

{文章源自略懂百科-http://wswcn.cn/107840.html

HWND hWndDlg = CreateDialogParam(hInst, "IDD_DIALOG1", NULL, (DLGPROC)WndDlg, NULL);文章源自略懂百科-http://wswcn.cn/107840.html

HWND hWndComboBox = GetDlgItem(hWndDlg, IDC_COMBO_SELECT_TYPE);文章源自略懂百科-http://wswcn.cn/107840.html

SendMessage(hWndComboBox, CB_ADDSTRING, 0, (LPARAM)TEXT("单击左键"));文章源自略懂百科-http://wswcn.cn/107840.html

SendMessage(hWndComboBox, CB_ADDSTRING, 0, (LPARAM)TEXT("双击左键"));文章源自略懂百科-http://wswcn.cn/107840.html

SendMessage(hWndComboBox, CB_SETCURSEL, 0, 0);文章源自略懂百科-http://wswcn.cn/107840.html

SYSTEMTIME st = { 2020,1,0,1,1,0,0,0 }; //默认设置持续1小时,当心此处的时间的有效性文章源自略懂百科-http://wswcn.cn/107840.html

SendMessage(GetDlgItem(hWndDlg, IDC_DTP_CONTINUE), DTM_SETSYSTEMTIME, GDT_VALID, (LPARAM)&st);文章源自略懂百科-http://wswcn.cn/107840.html

SetWindowText(GetDlgItem(hWndDlg, IDC_INTERVAL), "1000");文章源自略懂百科-http://wswcn.cn/107840.html

SetWindowText(hWndDlg, "鼠标模拟");文章源自略懂百科-http://wswcn.cn/107840.html

ShowWindow(hWndDlg, SW_SHOW);文章源自略懂百科-http://wswcn.cn/107840.html

//注册的热键尽量不要和其它程序注册的一样,否则会冲突,冲突后会失效,杀软等也会屏蔽热键和mouse_event文章源自略懂百科-http://wswcn.cn/107840.html

RegisterHotKey(hWndDlg, WM_MOUSE_POS, MOD_CONTROL | MOD_SHIFT, VK_F4);文章源自略懂百科-http://wswcn.cn/107840.html

RegisterHotKey(hWndDlg, WM_MOUSE_STOP, MOD_CONTROL | MOD_SHIFT, VK_F6);文章源自略懂百科-http://wswcn.cn/107840.html

MSG msg;文章源自略懂百科-http://wswcn.cn/107840.html

while (GetMessage(&msg, NULL, NULL, NULL)) {文章源自略懂百科-http://wswcn.cn/107840.html

//if (msg.message == WM_KEYDOWN) {文章源自略懂百科-http://wswcn.cn/107840.html

// if (msg.wParam == VK_F3) g_lockMouse = !g_lockMouse;文章源自略懂百科-http://wswcn.cn/107840.html

//}文章源自略懂百科-http://wswcn.cn/107840.html

if (!IsDialogMessage(hWndDlg, &msg)) {// 如果消息没有被处理, 返回值为0文章源自略懂百科-http://wswcn.cn/107840.html

TranslateMessage(&msg);文章源自略懂百科-http://wswcn.cn/107840.html

DispatchMessage(&msg);文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

UnregisterHotKey(hWndDlg, WM_MOUSE_POS);文章源自略懂百科-http://wswcn.cn/107840.html

UnregisterHotKey(hWndDlg, WM_MOUSE_STOP);文章源自略懂百科-http://wswcn.cn/107840.html

return 0;文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

void CALLBACK UpdateMousePosTimeProc(HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)文章源自略懂百科-http://wswcn.cn/107840.html

{文章源自略懂百科-http://wswcn.cn/107840.html

if (g_lockMouse) return;文章源自略懂百科-http://wswcn.cn/107840.html

GetCursorPos(&g_mousePos);文章源自略懂百科-http://wswcn.cn/107840.html

TCHAR str[64] = { 0 };文章源自略懂百科-http://wswcn.cn/107840.html

wsprintf(str, "%d , %d", g_mousePos);文章源自略懂百科-http://wswcn.cn/107840.html

SetWindowText(GetDlgItem(hwnd, IDC_MOUSE_POS), str);文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

void SetStartBtnState(HWND hwnd, BOOL state)文章源自略懂百科-http://wswcn.cn/107840.html

{文章源自略懂百科-http://wswcn.cn/107840.html

EnableWindow(GetDlgItem(hwnd, IDC_BTN_STOP), !state);文章源自略懂百科-http://wswcn.cn/107840.html

EnableWindow(GetDlgItem(hwnd, IDC_BTN_START), state);文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

//此处未处理开始和结束时间文章源自略懂百科-http://wswcn.cn/107840.html

void CALLBACK MouseClickTimeProc(HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)文章源自略懂百科-http://wswcn.cn/107840.html

{文章源自略懂百科-http://wswcn.cn/107840.html

SetCursorPos(g_mousePos.x, g_mousePos.y);文章源自略懂百科-http://wswcn.cn/107840.html

Sleep(200);文章源自略懂百科-http://wswcn.cn/107840.html

for (int i = 0; i <= g_clickType; i++) {文章源自略懂百科-http://wswcn.cn/107840.html

mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, g_mousePos.x, g_mousePos.y, 0, 0);文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

void StartMouseClickTimer(HWND hwnd)文章源自略懂百科-http://wswcn.cn/107840.html

{文章源自略懂百科-http://wswcn.cn/107840.html

TCHAR str[1024] = { 0 };文章源自略懂百科-http://wswcn.cn/107840.html

GetWindowText(GetDlgItem(hwnd, IDC_INTERVAL), str, 1000);文章源自略懂百科-http://wswcn.cn/107840.html

int inteval = atoi(str);文章源自略懂百科-http://wswcn.cn/107840.html

if (inteval < 100) {文章源自略懂百科-http://wswcn.cn/107840.html

MessageBox(hwnd, "间隔时间要大于等于100", "错误", MB_YESNO);文章源自略懂百科-http://wswcn.cn/107840.html

return;文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

g_clickType = SendMessage(GetDlgItem(hwnd, IDC_COMBO_SELECT_TYPE), CB_GETCURSEL, 0, 0);文章源自略懂百科-http://wswcn.cn/107840.html

SetTimer(hwnd, ID_TIMER_CLICK, inteval, MouseClickTimeProc);文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

BOOL CALLBACK WndDlg(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)文章源自略懂百科-http://wswcn.cn/107840.html

{文章源自略懂百科-http://wswcn.cn/107840.html

switch (message) {文章源自略懂百科-http://wswcn.cn/107840.html

case WM_INITDIALOG:文章源自略懂百科-http://wswcn.cn/107840.html

SetTimer(hwnd, ID_TIMER_MOUSE, 100, UpdateMousePosTimeProc);文章源自略懂百科-http://wswcn.cn/107840.html

SetStartBtnState(hwnd, TRUE);文章源自略懂百科-http://wswcn.cn/107840.html

return TRUE;文章源自略懂百科-http://wswcn.cn/107840.html

case WM_HOTKEY:文章源自略懂百科-http://wswcn.cn/107840.html

if (HIWORD(lParam) == VK_F4 && LOWORD(lParam) == (MOD_CONTROL | MOD_SHIFT)) {文章源自略懂百科-http://wswcn.cn/107840.html

g_lockMouse = !g_lockMouse;文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

if (HIWORD(lParam) == VK_F6 && LOWORD(lParam) == (MOD_CONTROL | MOD_SHIFT)) {文章源自略懂百科-http://wswcn.cn/107840.html

SetStartBtnState(hwnd, TRUE);文章源自略懂百科-http://wswcn.cn/107840.html

KillTimer(hwnd, ID_TIMER_CLICK);文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

return TRUE;文章源自略懂百科-http://wswcn.cn/107840.html

case WM_COMMAND:文章源自略懂百科-http://wswcn.cn/107840.html

switch (LOWORD(wParam)) {文章源自略懂百科-http://wswcn.cn/107840.html

case IDC_BTN_START:文章源自略懂百科-http://wswcn.cn/107840.html

SetStartBtnState(hwnd, FALSE);文章源自略懂百科-http://wswcn.cn/107840.html

StartMouseClickTimer(hwnd);文章源自略懂百科-http://wswcn.cn/107840.html

break;文章源自略懂百科-http://wswcn.cn/107840.html

case IDC_BTN_STOP:文章源自略懂百科-http://wswcn.cn/107840.html

SetStartBtnState(hwnd, TRUE);文章源自略懂百科-http://wswcn.cn/107840.html

KillTimer(hwnd, ID_TIMER_CLICK);文章源自略懂百科-http://wswcn.cn/107840.html

break;文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

return TRUE;文章源自略懂百科-http://wswcn.cn/107840.html

case WM_CLOSE:文章源自略懂百科-http://wswcn.cn/107840.html

KillTimer(hwnd, ID_TIMER_MOUSE);文章源自略懂百科-http://wswcn.cn/107840.html

KillTimer(hwnd, ID_TIMER_CLICK);文章源自略懂百科-http://wswcn.cn/107840.html

DestroyWindow(hwnd);文章源自略懂百科-http://wswcn.cn/107840.html

return TRUE;文章源自略懂百科-http://wswcn.cn/107840.html

case WM_DESTROY:文章源自略懂百科-http://wswcn.cn/107840.html

PostQuitMessage(0);文章源自略懂百科-http://wswcn.cn/107840.html

return TRUE;文章源自略懂百科-http://wswcn.cn/107840.html

default:文章源自略懂百科-http://wswcn.cn/107840.html

return FALSE;文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

return FALSE;文章源自略懂百科-http://wswcn.cn/107840.html

}文章源自略懂百科-http://wswcn.cn/107840.html

原创文章,请勿转载文章源自略懂百科-http://wswcn.cn/107840.html

文章源自略懂百科-http://wswcn.cn/107840.html

懵懂先生
  • 本文由 发表于 2023年4月10日 13:17:56
  • 转载请注明:http://wswcn.cn/107840.html
投稿文章

丸九鱼饵配方(5款超经典的饵料配方)

丸九鲤鱼饵料详解:荒食:配合集鱼、诱鱼性好的原材料制成的吸食超群的鱼饵。对钓鱼场的滑头鲤鱼,可揉和得软些,沉住气垂钓。重量:250G天下无双:是浮漂钓的鲤鱼专用饵。雾化性强吸引鲤鱼,饵芯挂钩好,易使其...
投稿文章

乌拉的使用有限制吗(女孩说乌拉是什么意思)

每个国家都有自己的文化传承,这既是对于这些文化的继承,又是在后续发展当中的一种延续。其实要是文化发展的话很多国家都会想到一些比较有文化底蕴的,而在当今世界的发展上,中国的历史可以说是久远的一个,而这些...
投稿文章

500万韩元等于多少人民币(一兆韩元等于多少亿)

文在寅中秋节为妻女切西瓜(资料图) 海外网12月26日电据韩联社12月26日报道,韩国前总统文在寅最近捐款500万韩元(约合人民币2.7万元),帮助生活有困难的邻里乡亲。不料这一消息被慈善组织公布后,...