How do I lock my keyboard with a hook

  • 2020-04-02 02:07:01
  • OfStack


#include 
#include 
//The procedure function that handles the key message
LRESULT CALLBACK keyproc( int code,
WPARAM wParam,
LPARAM lParam )
{
return 1;//Returning 1 causes the keyboard to stop responding
}
main(int argc, char* argv[])
{
SetWindowsHookEx(WH_KEYBOARD,keyproc,GetModuleHandle(NULL),0);//Install keyboard hook
printf("nnn Program will be 15 Wonderful then return ... Hey hey 15 Milne, your keyboard doesn't work n");
::Sleep(15000);
}

The key to using a hook in your code without a DLL is the GetModuleHandle(NULL), where the GetModuleHandle() parameter is NULL to get the module handle of the caller, that is, to use the program itself as a DLL. Because it is a console program, the hook is OVER when the program ends, so the hook is not unloaded.


Related articles: