#include <stdio.h>
#include <Windows.h>
#define TITLE_LEN 521
int main(int argc, char **argv)
{
char text[TITLE_LEN];
HWND preWindow = NULL;
while (1)
{
HWND window = GetForegroundWindow();
if (window != preWindow)
{
GetWindowText(window, text, TITLE_LEN);
printf("text: %s\n", text);
preWindow = window;
}
Sleep(10);//1000ms = 1s
char key = '0';
for (; key <= '9'; key++)
{
if (GetAsyncKeyState(key) & 0x8000)
{
while (GetAsyncKeyState(key) & 0x8000) Sleep(1);//等待键盘弹起
printf("按键 %c 被按下啦!!!\n", key);
}
}
for (key = 'a'; key <= 'z'; key++)
{
if (GetAsyncKeyState(key) & 0x8000)
{
while (GetAsyncKeyState(key) & 0x8000) Sleep(1);//等待键盘弹起
printf("按键 %c 被按下啦!!!\n", key);
}
}
}
system("pause");
return 0;
}
c语言实现窗口监控
最新推荐文章于 2023-10-15 17:11:54 发布