c++ - 在 Windows 8.1 中模拟按键

标签 c++ visual-c++ visual-studio-2013 windows-8.1

我一直在尝试制作一个垃圾左键点击程序,因为我的 friend 挑战我在 10 秒内点击次数比他多。

这是我的代码:

#include <stdio.h>
#include <iostream>
#include <Windows.h>

using namespace std;

bool should_click = false;
char in;

int main()
{

    INPUT ip;

    ip.type = INPUT_MOUSE;
    ip.ki.wScan = 0x01; //code for left click ^.^
    ip.ki.time = 0;
    ip.ki.dwExtraInfo = 0;

    while (!should_click)
    {
        cin >> in;
        if (in == 'g')
            should_click = true;
    }
    while (should_click)
    {
        // Press the key
        ip.ki.wVk = 0x01; // virtual-key code for mouse left click
        ip.ki.dwFlags = 0; // 0 for key press
        SendInput(1, &ip, sizeof(INPUT));

        // Release the key
        ip.ki.dwFlags = MOUSEEVENTF_LEFTUP; // KEYEVENTF_KEYUP for key release
        SendInput(1, &ip, sizeof(INPUT));

        Sleep(100);
    }

    return 0;

}

当我启动该程序并按 g 时,Windows 逐渐变黑,然后进入我的屏幕保护程序,然后每 100 毫秒返回一次桌面。我试过只模拟按键一次,结果也一样(只有一次)。

有解决办法吗?

PS:不,我无法在 10 秒内击败 96 次点击
PPS:我设法做到了。但我仍然想知道一种解决方法来制作一般的垃圾邮件发送者。

最佳答案

SendInput()可用于实现恶意软件。这就是为什么,ars 在 MSDN 上评论说,它受制于 UIPI。 .所以你只能通过以管理权限运行来摆脱这种奇怪的行为。

编辑:这个 MSDN article有一个关于 UIPI 的部分以及如何赋予应用程序绕过它的权利。它不仅涉及以管理员身份运行代码,还涉及在可执行文件的 list 中设置 UIAccess 属性,并使用有效证书签署代码。

关于c++ - 在 Windows 8.1 中模拟按键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30415176/

相关文章:

C++ - 你能假设 type* = std::array<type>::iterator 吗?

c++ - C++中的引用

c++ - 在 Visual Studio 和 GCC 中使用 STL 排序排序

c++编译器忽略第一个if语句

visual-studio-2013 - ExcludeFilesFromDeployment 在 Visual Studio 2013 Publish Web 中不起作用

c++ - 将动态特征向量的 vector 转换为字节

c++ - 重载 >> 运算符给我运行时错误 C++

c - 将显示正在运行的进程的 Windows API

visual-studio-2013 - 在 Visual Studio 2013 上安装 CRM 2015 SDK

tfs - 无法获得排队到 Controller 的 Visual Studio 2013 负载测试