Save shapeless app from closing for keyboard

I am working on a C ++ win32 program that includes a keyboard hook. The app is a win32 project without any user interface. I need to prevent the application from closing without using forcing the hook to fail or using a bunch of system resources. I used a message box, but I need the application to be completely invisible.

Any help would be appreciated!

If you have any questions, just ask.

+1


source to share


3 answers


I think you only need a message box



( MSDN says ). The message-only window allows you to send and receive messages. It is not displayed, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window just sends messages.

+7


source


Do you really need windows? MSDN page LowLevelKeyboardProc recommends using a simple message loop. Just paste this snippet after calling the call.



// message loop to keep the keyboard hook running
MSG msg;
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}

      

0


source


The best way would be to add a loop that keeps moving.

bool shouldExit = false;

do
{
   //some code to handle events
   shouldExit = handleEvents();

   //sleep for a small bit so we dont take up 100% cpu
   sleep(500);
}
while (!shouldExit);

      

-3


source







All Articles