C++ move mouse in windows using SetCursorPos

狂风中的少年 提交于 2019-11-30 08:38:21

You cannot set the cursor position or input of a window that required higher privileges than your program has..

If you want your program to be able to move the cursor over task manager, you require the same privileges as task manager: Administrator Privileges.

This is how it is done on Windows 8+.

I tried it with the following:

int main()
{
    HWND window = FindWindow("TaskManagerWindow", "Task Manager");
    if (window)
    {
        RECT rect = {0};
        GetWindowRect(window, &rect);

        SetForegroundWindow(window);
        SetActiveWindow(window);
        SetFocus(window);
        Sleep(300);
        SetCursorPos(rect.right - 200, rect.bottom - 200);
    }

    return 0;
}

Cursor only moves over task manager when ran as admin. It is the same for all context menus and windows in Windows 8+. Not just task manager.

Shagun verma - Developer
#include <Windows.h>

int main()
{
    SetCursorPos(200, 200);
    return 0;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!