自动单击程序

我写的程序交给测试组测试时, 经常需要自动单击功能-.-于是开发了这么一个自动单击工具.

包括的功能有:

1.设置鼠标

2.自动找按钮

3.设置触发频率.

 

工程见: https://files.cnblogs.com/lin1270/AutoClick_ex.zip

2012_04_19 最新修改:

1. 支持C#按钮单击。

2. 支持复选框、单选框、Static控件等单击。

C#的Link控件有问题,改成如下判断了。附件的代码并没有更改---

if (hwndParent != NULL && IsWindow (hwndParent)) {
                    DWORD dwStyle = GetWindowLong ((*it)->ctrl.hwnd, GWL_STYLE);
                    if (dwStyle & BS_PUSHBUTTON) {
                        PostMessage (hwndParent, WM_COMMAND, MAKEWPARAM (GetWindowLong ((*it)->ctrl.hwnd, GWL_ID),BN_CLICKED), (LPARAM)(*it)->ctrl.hwnd);
                    } else if ((dwStyle & 0x0000000D) == 0x0000000D) {
                        RECT rc;
                        GetWindowRect((*it)->ctrl.hwnd, &rc);

                        POINT ptOrigin;
                        GetCursorPos(&ptOrigin);

                        INPUT inputs = {0};
                        inputs.type = INPUT_MOUSE;
                        inputs.mi.dx = (rc.left + (rc.right - rc.left) / 2) * 65535 / GetSystemMetrics (SM_CXSCREEN);
                        inputs.mi.dy = (rc.top +  (rc.bottom - rc.top) / 2) * 65535 / GetSystemMetrics (SM_CYSCREEN);
                        inputs.mi.mouseData = 0;

                        inputs.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
                        SendInput (1, &inputs, sizeof (INPUT));
                        inputs.mi.dwFlags = MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE;
                        SendInput (1, &inputs, sizeof (INPUT));
                        inputs.mi.dwFlags = MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE;
                        SendInput (1, &inputs, sizeof (INPUT));


                        //SendMessage ((*it)->ctrl.hwnd, WM_LBUTTONDOWN, 0, 0);
                        //SendMessage ((*it)->ctrl.hwnd, WM_LBUTTONUP,   0, 0);
                        
                        memset (&inputs, 0, sizeof (INPUT));
                        inputs.type = INPUT_MOUSE;
                        inputs.mi.dx = ptOrigin.x  * 65535 / GetSystemMetrics (SM_CXSCREEN);
                        inputs.mi.dy = ptOrigin.y * 65535 / GetSystemMetrics (SM_CYSCREEN);
                        inputs.mi.mouseData = 0;
                        inputs.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
                        SendInput (1, &inputs, sizeof (INPUT));

                    } else {
                        PostMessage ((*it)->ctrl.hwnd, WM_LBUTTONDOWN, 0, 0);
                        PostMessage ((*it)->ctrl.hwnd, WM_LBUTTONUP,   0, 0);
                    }
                } else {
                    /**
                     * 如果没有父窗口的话, 还是发一个左键消息吧, 以免遗漏
                     */
                    PostMessage ((*it)->ctrl.hwnd, WM_LBUTTONDOWN, 0, 0);
                    PostMessage ((*it)->ctrl.hwnd, WM_LBUTTONUP,   0, 0);
                }

 

posted @ 2011-12-03 03:06  夜雨無聲  阅读(485)  评论(0编辑  收藏  举报